ZQuest Classic Coverage Report


Directory: src/
File: src/zc/zc_sys.cpp
Date: 2025-08-25 09:00:48
Exec Total Coverage
Lines: 1992 4575 43.5%
Functions: 127 337 37.7%
Branches: 1345 3764 35.7%

Line Branch Exec Source
1 #include "zc/zc_sys.h"
2
3 #include "allegro/gfx.h"
4 #include "allegro/gui.h"
5 #include "allegro/inline/draw.inl"
6 #include "allegro5/joystick.h"
7 #include "base/files.h"
8 #include "base/render.h"
9 #include "base/zdefs.h"
10 #include "zalleg/zalleg.h"
11 #include "base/qrs.h"
12 #include "base/dmap.h"
13 #include <functional>
14 #include <queue>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <cstring>
18 #include <math.h>
19 #include <map>
20 #include <filesystem>
21 #include <ctype.h>
22 #include <sstream>
23 #include "base/version.h"
24 #include "base/zc_alleg.h"
25 #include "gamedata.h"
26 #include "zc/frame_timings.h"
27 #include "zc/replay_upload.h"
28 #include "zc/zc_init.h"
29 #include "init.h"
30 #include "zc/replay.h"
31 #include "zc/cheats.h"
32 #include "zc/render.h"
33 #include "base/zc_math.h"
34 #include "base/zapp.h"
35 #include "dialog/cheatkeys.h"
36 #include "metadata/metadata.h"
37 #include "zc/zelda.h"
38 #include "zc/saves.h"
39 #include "tiles.h"
40 #include "base/colors.h"
41 #include "pal.h"
42 #include "base/zsys.h"
43 #include "base/qst.h"
44 #include "zc/zc_sys.h"
45 #include "play_midi.h"
46 #include "gui/jwin_a5.h"
47 #include "base/jwinfsel.h"
48 #include "base/gui.h"
49 #include "midi.h"
50 #include "subscr.h"
51 #include "zc/maps.h"
52 #include "sprite.h"
53 #include "zc/guys.h"
54 #include "zc/hero.h"
55 #include "zc/title.h"
56 #include "particles.h"
57 #include "sound/zcmusic.h"
58 #include "zc/ffscript.h"
59 #include "dialog/info.h"
60 #include "dialog/alert.h"
61 #include "zc/combos.h"
62 #include "zc/jit.h"
63 #include "zc/zc_subscr.h"
64 #include <fmt/format.h>
65 #include "zconsole/ConsoleLogger.h"
66 #include "zinfo.h"
67 #include "base/misctypes.h"
68 #include "music_playback.h"
69 #include "base/new_menu.h"
70 #include "base/files.h"
71 #include "iter.h"
72
73 #ifdef __EMSCRIPTEN__
74 #include "base/emscripten_utils.h"
75 #endif
76
77 using namespace std::chrono_literals;
78
79 extern bool Playing;
80 int32_t sfx_voice[WAV_COUNT];
81 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c);
82 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c);
83
84 static ALLEGRO_JOYSTICK* gamepad_dlg_cur_joystick;
85 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c);
86
87 extern byte monochrome_console;
88
89 extern sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations;
90 extern std::string loadlast;
91 extern char *sfx_string[WAV_COUNT];
92 byte use_dwm_flush;
93 byte use_save_indicator;
94 int32_t paused_midi_pos = 0;
95 byte midi_suspended = 0;
96 byte zc_192b163_warp_compatibility;
97 bool epilepsyFlashReduction;
98 signed char pause_in_background_menu_init = 0;
99 byte pause_in_background = 0;
100 bool is_sys_pal = false;
101 static bool load_control_called_this_frame;
102 extern PALETTE* hw_palette;
103 extern bool update_hw_pal;
104 extern const char* dmaplist(int32_t index, int32_t* list_size);
105 int32_t getnumber(const char *prompt,int32_t initialval);
106
107 extern bool kb_typing_mode; //script only, for disbaling key presses affecting Hero, etc.
108 extern int32_t cheat_modifier_keys[4]; //two options each, default either control and either shift
109
110 #ifdef ALLEGRO_LINUX
111 static const char *samplepath = "samplesoundset/patches.dat";
112 #endif
113 char qst_files_path[2048];
114
115 extern TopMenu the_player_menu;
116 #ifdef _MSC_VER
117 #define getcwd _getcwd
118 #endif
119
120 bool rF11();
121 bool rI();
122 bool rQ();
123 bool zc_key_pressed();
124
125 #ifdef _WIN32
126
127 // This should only be necessary for MinGW, since it doesn't have a dwmapi.h. Add another #ifdef if you like.
128 extern "C"
129 {
130 typedef HRESULT(WINAPI *t_DwmFlush)();
131 typedef HRESULT(WINAPI *t_DwmIsCompositionEnabled)(BOOL *pfEnabled);
132 }
133
134 void do_DwmFlush()
135 {
136 static HMODULE shell = LoadLibrary("dwmapi.dll");
137
138 if(!shell)
139 return;
140
141 static t_DwmFlush flush=reinterpret_cast<t_DwmFlush>(GetProcAddress(shell, "DwmFlush"));
142 static t_DwmIsCompositionEnabled isEnabled=reinterpret_cast<t_DwmIsCompositionEnabled>(GetProcAddress(shell, "DwmIsCompositionEnabled"));
143
144 BOOL enabled;
145 isEnabled(&enabled);
146
147 if(isEnabled)
148 flush();
149 }
150
151 #endif // _WIN32
152
153 313 void zc_exit(int code)
154 {
155 extern CConsoleLoggerEx zscript_coloured_console;
156
157 313 set_is_exiting();
158
159
1/2
✓ Branch 0 taken 313 times.
✗ Branch 1 not taken.
313 if (replay_get_mode() == ReplayMode::Record) replay_save();
160 313 replay_stop();
161 313 music_stop();
162 313 kill_sfx();
163
164
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 305 times.
313 if (get_qr(qr_OLD_SCRIPT_VOLUME))
165 {
166 //restore user volume settings
167
2/2
✓ Branch 0 taken 304 times.
✓ Branch 1 taken 1 times.
305 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
168 {
169 1 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
170 1 }
171
2/2
✓ Branch 0 taken 304 times.
✓ Branch 1 taken 1 times.
305 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
172 {
173 1 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
174 1 }
175
2/2
✓ Branch 0 taken 304 times.
✓ Branch 1 taken 1 times.
305 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
176 {
177 1 emusic_volume = (int32_t)FFCore.usr_music_volume;
178 1 }
179
1/2
✓ Branch 0 taken 305 times.
✗ Branch 1 not taken.
305 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
180 {
181 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
182 }
183 305 }
184
1/2
✓ Branch 0 taken 313 times.
✗ Branch 1 not taken.
313 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
185 {
186 pan_style = (int32_t)FFCore.usr_panstyle;
187 }
188 313 save_game_configs();
189
190 313 zscript_coloured_console.kill();
191 313 jit_shutdown();
192 313 frame_timings_end();
193 313 quit_game();
194
195 313 Z_message("ZQuest Classic website: https://zquestclassic.com\n");
196 313 Z_message("ZQuest Classic docs: https://docs.zquestclassic.com\n");
197
198 313 allegro_exit();
199 313 exit(code);
200 }
201
202 93594 bool flash_reduction_enabled(bool check_qr)
203 {
204
4/4
✓ Branch 0 taken 88914 times.
✓ Branch 1 taken 4680 times.
✓ Branch 2 taken 87624 times.
✓ Branch 3 taken 92304 times.
93594 return (check_qr && get_qr(qr_EPILEPSY)) || epilepsyFlashReduction || replay_is_debug();
205 }
206
207 // Dialogue largening
208 void large_dialog(DIALOG *d)
209 {
210 large_dialog(d, 1.5);
211 }
212
213 void large_dialog(DIALOG *d, float RESIZE_AMT)
214 {
215 if(!d[0].d1)
216 {
217 d[0].d1 = 1;
218 int32_t oldwidth = d[0].w;
219 int32_t oldheight = d[0].h;
220 int32_t oldx = d[0].x;
221 int32_t oldy = d[0].y;
222 d[0].x -= int32_t(d[0].w/RESIZE_AMT);
223 d[0].y -= int32_t(d[0].h/RESIZE_AMT);
224 d[0].w = int32_t(d[0].w*RESIZE_AMT);
225 d[0].h = int32_t(d[0].h*RESIZE_AMT);
226
227 for(int32_t i=1; d[i].proc !=NULL; i++)
228 {
229 // Place elements horizontally
230 double xpc = ((double)(d[i].x - oldx) / (double)oldwidth);
231 d[i].x = int32_t(d[0].x + (xpc*d[0].w));
232
233 if(d[i].proc != d_stringloader)
234 {
235 if(d[i].proc==d_bitmap_proc)
236 {
237 d[i].w *= 2;
238 }
239 else d[i].w = int32_t(d[i].w*RESIZE_AMT);
240 }
241
242 // Place elements vertically
243 double ypc = ((double)(d[i].y - oldy) / (double)oldheight);
244 d[i].y = int32_t(d[0].y + (ypc*d[0].h));
245
246 // Vertically resize elements
247 if(d[i].proc == jwin_edit_proc || d[i].proc == jwin_check_proc || d[i].proc == jwin_checkfont_proc)
248 {
249 d[i].h = int32_t((double)d[i].h*1.5);
250 }
251 else if(d[i].proc == jwin_droplist_proc || d[i].proc == d_joylist_proc)
252 {
253 d[i].y += int32_t((double)d[i].h*0.25);
254 d[i].h = int32_t((double)d[i].h*1.25);
255 }
256 else if(d[i].proc==d_bitmap_proc)
257 {
258 d[i].h *= 2;
259 }
260 else d[i].h = int32_t(d[i].h*RESIZE_AMT);
261
262 // Fix frames
263 if(d[i].proc == jwin_frame_proc)
264 {
265 d[i].x++;
266 d[i].y++;
267 d[i].w-=4;
268 d[i].h-=4;
269 }
270 }
271 }
272
273 for(int32_t i=1; d[i].proc!=NULL; i++)
274 {
275 if(d[i].proc==jwin_slider_proc)
276 continue;
277
278 // Bigger font
279 bool bigfontproc = (d[i].proc != d_midilist_proc && d[i].proc != jwin_droplist_proc && d[i].proc != jwin_abclist_proc && d[i].proc != jwin_list_proc && d[i].proc != d_joylist_proc);
280
281 if(!d[i].dp2 && bigfontproc)
282 {
283 d[i].dp2 = get_zc_font(font_lfont_l);
284 }
285 else if(!bigfontproc)
286 {
287 ((ListData *)d[i].dp)->font = &a4fonts[font_lfont_l];
288 }
289
290 // Make checkboxes work
291 if(d[i].proc == jwin_check_proc)
292 d[i].proc = jwin_checkfont_proc;
293 else if(d[i].proc == jwin_radio_proc)
294 d[i].proc = jwin_radiofont_proc;
295 }
296
297 jwin_center_dialog(d);
298 }
299
300 static char cfg_sect[] = "zeldadx"; //We need to rename this.
301 static char ctrl_sect[] = "Controls";
302 static char sfx_sect[] = "Volume";
303
304 int32_t d_dummy_proc(int32_t,DIALOG *,int32_t)
305 {
306 return D_O_K;
307 }
308
309 bool is_reserved_key(int c)
310 {
311 switch(c)
312 {
313 case KEY_ESC:
314 return true;
315 }
316 return false;
317 }
318 bool is_reserved_keycombo(int c, int modflag)
319 {
320 if(c==KEY_F4 && (modflag&KB_ALT_FLAG))
321 return true;
322 return false;
323 }
324 bool checkcheat(Cheat cheat)
325 {
326 if(cheatkeys[cheat][0] && zc_readkey(cheatkeys[cheat][0]))
327 return true; //Main key pressed
328 if(cheatkeys[cheat][1] && zc_readkey(cheatkeys[cheat][1]))
329 return true; //Alt key pressed
330 return false;
331 }
332 313 void load_default_cheatkeys()
333 {
334 313 memset(cheatkeys, 0, sizeof(cheatkeys));
335 313 cheatkeys[Cheat::Life][0] = KEY_H;
336 313 cheatkeys[Cheat::Life][1] = KEY_ASTERISK;
337 313 cheatkeys[Cheat::Magic][0] = KEY_M;
338 313 cheatkeys[Cheat::Magic][1] = KEY_SLASH_PAD;
339 313 cheatkeys[Cheat::Rupies][0] = KEY_R;
340 313 cheatkeys[Cheat::Bombs][0] = KEY_B;
341 313 cheatkeys[Cheat::Arrows][0] = KEY_A;
342 313 cheatkeys[Cheat::Clock][0] = KEY_I;
343 313 cheatkeys[Cheat::Walls][0] = KEY_F11;
344 313 cheatkeys[Cheat::Fast][0] = KEY_Q;
345 313 cheatkeys[Cheat::Light][0] = KEY_L;
346 313 cheatkeys[Cheat::IgnoreSideView][0] = KEY_V;
347 313 cheatkeys[Cheat::Kill][0] = KEY_K;
348 313 cheatkeys[Cheat::GoTo][0] = KEY_G;
349 313 cheatkeys[Cheat::TrigSecrets][0] = KEY_S;
350 313 cheatkeys[Cheat::ShowL0][0] = KEY_0;
351 313 cheatkeys[Cheat::ShowL1][0] = KEY_1;
352 313 cheatkeys[Cheat::ShowL2][0] = KEY_2;
353 313 cheatkeys[Cheat::ShowL3][0] = KEY_3;
354 313 cheatkeys[Cheat::ShowL4][0] = KEY_4;
355 313 cheatkeys[Cheat::ShowL5][0] = KEY_5;
356 313 cheatkeys[Cheat::ShowL6][0] = KEY_6;
357 313 cheatkeys[Cheat::ShowFFC][0] = KEY_7;
358 313 cheatkeys[Cheat::ShowSprites][0] = KEY_8;
359 313 cheatkeys[Cheat::ShowWalkability][0] = KEY_W;
360 313 cheatkeys[Cheat::ShowEffects][0] = KEY_E;
361 313 cheatkeys[Cheat::ShowOverhead][0] = KEY_O;
362 313 cheatkeys[Cheat::ShowPushblock][0] = KEY_P;
363 313 cheatkeys[Cheat::ShowHitbox][0] = KEY_C;
364 313 cheatkeys[Cheat::ShowFFCScripts][0] = KEY_F;
365 313 }
366
367 static bool loaded_game_configs;
368
369 313 void load_game_configs()
370 {
371 313 loaded_game_configs = true;
372 313 joystick_index = zc_get_config(ctrl_sect,"joystick_index",0);
373 313 js_stick_1_x_stick = zc_get_config(ctrl_sect,"js_stick_1_x_stick",0);
374 313 js_stick_1_x_axis = zc_get_config(ctrl_sect,"js_stick_1_x_axis",0);
375 313 js_stick_1_x_offset = zc_get_config(ctrl_sect,"js_stick_1_x_offset",0) ? 128 : 0;
376 313 js_stick_1_y_stick = zc_get_config(ctrl_sect,"js_stick_1_y_stick",0);
377 313 js_stick_1_y_axis = zc_get_config(ctrl_sect,"js_stick_1_y_axis",1);
378 313 js_stick_1_y_offset = zc_get_config(ctrl_sect,"js_stick_1_y_offset",0) ? 128 : 0;
379 313 js_stick_2_x_stick = zc_get_config(ctrl_sect,"js_stick_2_x_stick",1);
380 313 js_stick_2_x_axis = zc_get_config(ctrl_sect,"js_stick_2_x_axis",0);
381 313 js_stick_2_x_offset = zc_get_config(ctrl_sect,"js_stick_2_x_offset",0) ? 128 : 0;
382 313 js_stick_2_y_stick = zc_get_config(ctrl_sect,"js_stick_2_y_stick",1);
383 313 js_stick_2_y_axis = zc_get_config(ctrl_sect,"js_stick_2_y_axis",1);
384 313 js_stick_2_y_offset = zc_get_config(ctrl_sect,"js_stick_2_y_offset",0) ? 128 : 0;
385 313 analog_movement = (zc_get_config(ctrl_sect,"analog_movement",1));
386
387 //cheat modifier keya
388 313 cheat_modifier_keys[0] = zc_get_config(ctrl_sect,"key_cheatmod_a1",KEY_ZC_LCONTROL);
389 313 cheat_modifier_keys[1] = zc_get_config(ctrl_sect,"key_cheatmod_a2",0);
390 313 cheat_modifier_keys[2] = zc_get_config(ctrl_sect,"key_cheatmod_b1",KEY_ZC_RCONTROL);
391 313 cheat_modifier_keys[3] = zc_get_config(ctrl_sect,"key_cheatmod_b2",0);
392
393 //cheat keys
394 313 load_default_cheatkeys();
395 char buf[256];
396
2/2
✓ Branch 0 taken 313 times.
✓ Branch 1 taken 11268 times.
11581 for(size_t q = 1; q < Cheat::Last; ++q)
397 {
398
1/2
✓ Branch 0 taken 11268 times.
✗ Branch 1 not taken.
11268 if(!bindable_cheat((Cheat)q)) continue;
399 11268 std::string cheatname = cheat_to_string((Cheat)q);
400
1/2
✓ Branch 0 taken 11268 times.
✗ Branch 1 not taken.
11268 util::lowerstr(cheatname);
401 11268 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
402
1/2
✓ Branch 0 taken 11268 times.
✗ Branch 1 not taken.
11268 cheatkeys[q][0] = zc_get_config(ctrl_sect,buf,cheatkeys[q][0]);
403 11268 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
404
1/2
✓ Branch 0 taken 11268 times.
✗ Branch 1 not taken.
11268 cheatkeys[q][1] = zc_get_config(ctrl_sect,buf,cheatkeys[q][1]);
405 11268 }
406
407
1/2
✓ Branch 0 taken 313 times.
✗ Branch 1 not taken.
313 if((uint32_t)joystick_index >= MAX_JOYSTICKS)
408 joystick_index = 0;
409
410 313 Akey = zc_get_config(ctrl_sect,"key_a",KEY_Z);
411 313 Bkey = zc_get_config(ctrl_sect,"key_b",KEY_X);
412 313 Skey = zc_get_config(ctrl_sect,"key_s",KEY_ENTER);
413 313 Lkey = zc_get_config(ctrl_sect,"key_l",KEY_Q);
414 313 Rkey = zc_get_config(ctrl_sect,"key_r",KEY_W);
415 313 Pkey = zc_get_config(ctrl_sect,"key_p",KEY_SPACE);
416 313 Exkey1 = zc_get_config(ctrl_sect,"key_ex1",KEY_A);
417 313 Exkey2 = zc_get_config(ctrl_sect,"key_ex2",KEY_S);
418 313 Exkey3 = zc_get_config(ctrl_sect,"key_ex3",KEY_D);
419 313 Exkey4 = zc_get_config(ctrl_sect,"key_ex4",KEY_C);
420
421 313 DUkey = zc_get_config(ctrl_sect,"key_up", KEY_UP);
422 313 DDkey = zc_get_config(ctrl_sect,"key_down", KEY_DOWN);
423 313 DLkey = zc_get_config(ctrl_sect,"key_left", KEY_LEFT);
424 313 DRkey = zc_get_config(ctrl_sect,"key_right",KEY_RIGHT);
425
426 313 Abtn = zc_get_config(ctrl_sect,"btn_a",2);
427 313 Bbtn = zc_get_config(ctrl_sect,"btn_b",1);
428 313 Sbtn = zc_get_config(ctrl_sect,"btn_s",10);
429 313 Mbtn = zc_get_config(ctrl_sect,"btn_m",9);
430 313 Lbtn = zc_get_config(ctrl_sect,"btn_l",5);
431 313 Rbtn = zc_get_config(ctrl_sect,"btn_r",6);
432 313 Pbtn = zc_get_config(ctrl_sect,"btn_p",12);
433 313 Exbtn1 = zc_get_config(ctrl_sect,"btn_ex1",7);
434 313 Exbtn2 = zc_get_config(ctrl_sect,"btn_ex2",8);
435 313 Exbtn3 = zc_get_config(ctrl_sect,"btn_ex3",4);
436 313 Exbtn4 = zc_get_config(ctrl_sect,"btn_ex4",3);
437
438 313 DUbtn = zc_get_config(ctrl_sect,"btn_up",13);
439 313 DDbtn = zc_get_config(ctrl_sect,"btn_down",14);
440 313 DLbtn = zc_get_config(ctrl_sect,"btn_left",15);
441 313 DRbtn = zc_get_config(ctrl_sect,"btn_right",16);
442
443 313 epilepsyFlashReduction = zc_get_config(cfg_sect,"epilepsy_flash_reduction",0);
444
445 313 midi_volume = zc_get_config(sfx_sect,"midi",255);
446 313 sfx_volume = zc_get_config(sfx_sect,"sfx",255);
447 313 emusic_volume = zc_get_config(sfx_sect,"emusic",255);
448 313 pan_style = zc_get_config(sfx_sect,"pan",1);
449 313 volkeys = zc_get_config(sfx_sect,"volkeys",0)!=0;
450 313 zc_vsync = zc_get_config(cfg_sect,"vsync",0);
451 313 Throttlefps = zc_get_config(cfg_sect,"throttlefps",1)!=0;
452 313 Maxfps = zc_get_config(cfg_sect,"maxfps",0);
453 313 TransLayers = zc_get_config(cfg_sect,"translayers",1)!=0;
454 313 SnapshotFormat = zc_get_config(cfg_sect,"snapshot_format",3);
455 313 ShowBottomPixels = zc_get_config(cfg_sect,"bottom_8_px",0);
456 313 SnapshotScale = zc_get_config(cfg_sect,"snapshot_scale",2);
457 313 NameEntryMode = zc_get_config(cfg_sect,"name_entry_mode",0);
458 #ifdef __EMSCRIPTEN__
459 if (em_is_mobile()) NameEntryMode = 2;
460 #endif
461 313 ShowFPS = zc_get_config(cfg_sect,"showfps",0)!=0;
462 313 ShowGameTime = zc_get_config(cfg_sect,"showtime",0);
463 313 NESquit = zc_get_config(cfg_sect,"fastquit",0)!=0;
464 313 ClickToFreeze = zc_get_config(cfg_sect,"clicktofreeze",1)!=0;
465 313 abc_patternmatch = zc_get_config(cfg_sect, "lister_pattern_matching", 1);
466 313 pause_in_background = zc_get_config(cfg_sect, "pause_in_background", 0);
467
468 313 window_width = resx = zc_get_config(cfg_sect,"window_width",-1);
469 313 window_height = resy = zc_get_config(cfg_sect,"window_height",-1);
470 313 SaveDragResize = zc_get_config(cfg_sect,"save_drag_resize",0)!=0;
471 313 DragAspect = zc_get_config(cfg_sect,"drag_aspect",0)!=0;
472 313 SaveWinPos = zc_get_config(cfg_sect,"save_window_position",0)!=0;
473 313 scaleForceInteger = zc_get_config("zeldadx","scaling_force_integer",1)!=0;
474 313 stretchGame = zc_get_config("zeldadx","stretch_game_area",0)!=0;
475
476 313 loadlast = zc_get_config(cfg_sect,"load_last_path","");
477
478 313 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
479
480 313 info_opacity = zc_get_config("zc","debug_info_opacity",255);
481 #ifdef _WIN32
482 console_enabled = (byte) zc_get_config("CONSOLE", "enabled", 0);
483 //use_win7_keyboard_fix = (byte) zc_get_config(cfg_sect,"use_win7_key_fix",0);
484 use_win32_proc = (byte) zc_get_config(cfg_sect,"zc_win_proc_fix",0); //buggy
485
486 // This one's for Aero
487 use_dwm_flush = (byte) zc_get_config("zeldadx","use_dwm_flush",0);
488
489 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
490 #else //UNIX
491 313 console_enabled = (byte) zc_get_config("CONSOLE", "enabled", 0);
492 313 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
493 #endif
494 313 clearConsoleOnLoad = zc_get_config("CONSOLE","clear_console_on_load",1)!=0;
495 313 clearConsoleOnReload = zc_get_config("CONSOLE","clear_console_on_reload",0)!=0;
496
497 313 strcpy(qstdir,zc_get_config(cfg_sect,"quest_dir","quests"));
498 313 strcpy(qstpath,qstdir); //qstpath is the local (for this run of ZC) quest path, qstdir is the universal quest dir.
499 313 ss_enable = zc_get_config(cfg_sect,"ss_enable",1) ? 1 : 0;
500 313 ss_after = vbound(zc_get_config(cfg_sect,"ss_after",14), 0, 14);
501 313 ss_speed = vbound(zc_get_config(cfg_sect,"ss_speed",2), 0, 6);
502 313 ss_density = vbound(zc_get_config(cfg_sect,"ss_density",3), 0, 6);
503 313 heart_beep = zc_get_config(cfg_sect,"heart_beep",0)!=0;
504 //gui_colorset = zc_get_config(cfg_sect,"gui_colorset",0);
505 313 sfxdat = zc_get_config(cfg_sect,"use_sfx_dat",1); // TODO: sfxdat is always set to 1 for titlescreen... and 0 in readsfx... so this cfg is pointless, remove?
506 313 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
507 313 use_save_indicator = zc_get_config(cfg_sect,"save_indicator",0);
508 313 zc_192b163_warp_compatibility = zc_get_config(cfg_sect,"zc_192b163_warp_compatibility",0);
509 313 SkipTitle = zc_get_config(cfg_sect,"skip_title",0);
510 313 }
511
512 void save_control_configs(bool kb)
513 {
514 if(kb)
515 {
516 zc_set_config(ctrl_sect,"key_cheatmod_a1",cheat_modifier_keys[0]);
517 zc_set_config(ctrl_sect,"key_cheatmod_a2",cheat_modifier_keys[1]);
518 zc_set_config(ctrl_sect,"key_cheatmod_b1",cheat_modifier_keys[2]);
519 zc_set_config(ctrl_sect,"key_cheatmod_b2",cheat_modifier_keys[3]);
520
521 if (!replay_is_replaying())
522 {
523 zc_set_config(ctrl_sect,"key_a",Akey);
524 zc_set_config(ctrl_sect,"key_b",Bkey);
525 zc_set_config(ctrl_sect,"key_s",Skey);
526 zc_set_config(ctrl_sect,"key_l",Lkey);
527 zc_set_config(ctrl_sect,"key_r",Rkey);
528 zc_set_config(ctrl_sect,"key_p",Pkey);
529 zc_set_config(ctrl_sect,"key_ex1",Exkey1);
530 zc_set_config(ctrl_sect,"key_ex2",Exkey2);
531 zc_set_config(ctrl_sect,"key_ex3",Exkey3);
532 zc_set_config(ctrl_sect,"key_ex4",Exkey4);
533 zc_set_config(ctrl_sect,"key_up", DUkey);
534 zc_set_config(ctrl_sect,"key_down", DDkey);
535 zc_set_config(ctrl_sect,"key_left", DLkey);
536 zc_set_config(ctrl_sect,"key_right",DRkey);
537 }
538 }
539 else
540 {
541 zc_set_config(ctrl_sect,"joystick_index",joystick_index);
542 zc_set_config(ctrl_sect,"js_stick_1_x_stick",js_stick_1_x_stick);
543 zc_set_config(ctrl_sect,"js_stick_1_x_axis",js_stick_1_x_axis);
544 zc_set_config(ctrl_sect,"js_stick_1_x_offset",js_stick_1_x_offset ? 1 : 0);
545 zc_set_config(ctrl_sect,"js_stick_1_y_stick",js_stick_1_y_stick);
546 zc_set_config(ctrl_sect,"js_stick_1_y_axis",js_stick_1_y_axis);
547 zc_set_config(ctrl_sect,"js_stick_1_y_offset",js_stick_1_y_offset ? 1 : 0);
548 zc_set_config(ctrl_sect,"js_stick_2_x_stick",js_stick_2_x_stick);
549 zc_set_config(ctrl_sect,"js_stick_2_x_axis",js_stick_2_x_axis);
550 zc_set_config(ctrl_sect,"js_stick_2_x_offset",js_stick_2_x_offset ? 1 : 0);
551 zc_set_config(ctrl_sect,"js_stick_2_y_stick",js_stick_2_y_stick);
552 zc_set_config(ctrl_sect,"js_stick_2_y_axis",js_stick_2_y_axis);
553 zc_set_config(ctrl_sect,"js_stick_2_y_offset",js_stick_2_y_offset ? 1 : 0);
554 zc_set_config(ctrl_sect,"analog_movement",analog_movement);
555
556 zc_set_config(ctrl_sect,"btn_a",Abtn);
557 zc_set_config(ctrl_sect,"btn_b",Bbtn);
558 zc_set_config(ctrl_sect,"btn_s",Sbtn);
559 zc_set_config(ctrl_sect,"btn_m",Mbtn);
560 zc_set_config(ctrl_sect,"btn_l",Lbtn);
561 zc_set_config(ctrl_sect,"btn_r",Rbtn);
562 zc_set_config(ctrl_sect,"btn_p",Pbtn);
563 zc_set_config(ctrl_sect,"btn_ex1",Exbtn1);
564 zc_set_config(ctrl_sect,"btn_ex2",Exbtn2);
565 zc_set_config(ctrl_sect,"btn_ex3",Exbtn3);
566 zc_set_config(ctrl_sect,"btn_ex4",Exbtn4);
567
568 zc_set_config(ctrl_sect,"btn_up",DUbtn);
569 zc_set_config(ctrl_sect,"btn_down",DDbtn);
570 zc_set_config(ctrl_sect,"btn_left",DLbtn);
571 zc_set_config(ctrl_sect,"btn_right",DRbtn);
572 }
573 }
574
575 void save_cheatkeys()
576 {
577 char buf[256];
578 for(size_t q = 1; q < Cheat::Last; ++q)
579 {
580 if(!bindable_cheat((Cheat)q)) continue;
581 std::string cheatname = cheat_to_string((Cheat)q);
582 util::lowerstr(cheatname);
583 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
584 zc_set_config(ctrl_sect,buf,cheatkeys[q][0]);
585 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
586 if(cheatkeys[q][1])
587 zc_set_config(ctrl_sect,buf,cheatkeys[q][1]);
588 else zc_set_config(ctrl_sect,buf,(char*)nullptr);
589 }
590 }
591
592 313 void save_game_configs()
593 {
594
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 313 times.
313 if (!loaded_game_configs) return;
595
596 313 packfile_password("");
597
598
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 313 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
313 if (all_get_display() && !all_get_fullscreen_flag()&& SaveWinPos)
599 {
600 int o_window_x, o_window_y;
601 al_get_window_position(all_get_display(), &o_window_x, &o_window_y);
602 zc_set_config(cfg_sect,"window_x",o_window_x);
603 zc_set_config(cfg_sect,"window_y",o_window_y);
604 }
605
606
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 313 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
313 if (all_get_display() && !all_get_fullscreen_flag() && SaveDragResize)
607 {
608 window_width = al_get_display_width(all_get_display());
609 window_height = al_get_display_height(all_get_display());
610 zc_set_config(cfg_sect,"window_width",window_width);
611 zc_set_config(cfg_sect,"window_height",window_height);
612 }
613
614 313 zc_set_config(cfg_sect,"load_last_path",loadlast.c_str());
615 313 zc_set_config(cfg_sect,"use_sfx_dat",sfxdat);
616
617 313 flush_config_file();
618 #ifdef __EMSCRIPTEN__
619 em_sync_fs();
620 #endif
621 313 }
622
623 //----------------------------------------------------------------
624
625 // Timers
626
627 44347 void fps_callback()
628 {
629 44347 lastfps=framecnt;
630 44347 framecnt=0;
631 44347 }
632
633 END_OF_FUNCTION(fps_callback)
634
635 313 int32_t Z_init_timers()
636 {
637 static bool didit = false;
638 const static char *err_str = "Couldn't allocate timer";
639 313 err_str = err_str; //Unused variable warning
640
641
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 313 times.
313 if(didit)
642 return 1;
643
644 313 didit = true;
645
646 LOCK_VARIABLE(lastfps);
647 LOCK_VARIABLE(framecnt);
648 LOCK_FUNCTION(fps_callback);
649
650
1/2
✓ Branch 0 taken 313 times.
✗ Branch 1 not taken.
313 if(install_int_ex(fps_callback,SECS_TO_TIMER(1)))
651 return 0;
652
653 313 return 1;
654 313 }
655
656 313 void Z_remove_timers()
657 {
658 313 remove_int(fps_callback);
659 313 }
660
661 //----------------------------------------------------------------
662
663 void go()
664 {
665 blit(screen,tmp_scr,scrx,scry,0,0,screen->w,screen->h);
666 }
667
668 void comeback()
669 {
670 blit(tmp_scr,screen,0,0,scrx,scry,screen->w,screen->h);
671 }
672
673 void dump_pal(BITMAP *dest)
674 {
675 for(int32_t i=0; i<256; i++)
676 rectfill(dest,(i&63)<<2,(i&0xFC0)>>4,((i&63)<<2)+3,((i&0xFC0)>>4)+3,i);
677 }
678
679 //----------------------------------------------------------------
680
681 int game_mouse_index = ZCM_BLANK;
682 static bool system_mouse = false;
683 92 bool sys_mouse()
684 {
685 92 system_mouse = true;
686 92 return MouseSprite::set(ZCM_NORMAL);
687 }
688 1626 bool game_mouse()
689 {
690 1626 system_mouse = false;
691 1626 return MouseSprite::set(game_mouse_index);
692 }
693 void custom_mouse(BITMAP* bmp, int fx, int fy, bool sys_recolor, bool user_scale)
694 {
695 if(!bmp)
696 return;
697 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
698 int scaledw = bmp->w*scale, scaledh = bmp->h*scale;
699 if(bmp->w == scaledw && bmp->h == scaledh)
700 user_scale = false;
701 if(user_scale || sys_recolor)
702 {
703 if(!user_scale) scale = 1;
704 BITMAP* tmpbmp = create_bitmap_ex(8,bmp->w*scale,bmp->h*scale);
705 if(user_scale)
706 stretch_blit(bmp, tmpbmp, 0, 0, bmp->w, bmp->h, 0, 0, tmpbmp->w, tmpbmp->h);
707 else
708 blit(bmp, tmpbmp, 0, 0, 0, 0, bmp->w, bmp->h);
709 if(sys_recolor)
710 recolor_mouse(tmpbmp);
711 MouseSprite::assign(ZCM_CUSTOM, tmpbmp, fx*scale, fy*scale);
712 destroy_bitmap(tmpbmp);
713 }
714 else
715 {
716 MouseSprite::assign(ZCM_CUSTOM, bmp, fx, fy);
717 }
718 }
719
720 //Handles converting the mouse sprite from the .dat file
721 void recolor_mouse(BITMAP* bmp)
722 {
723 for(int32_t x = 0; x < bmp->w; ++x)
724 {
725 for(int32_t y = 0; y < bmp->h; ++y)
726 {
727 int32_t color = getpixel(bmp, x, y);
728 switch(color)
729 {
730 case dvc(1):
731 color = jwin_pal[jcCURSORMISC];
732 break;
733 case dvc(2):
734 color = jwin_pal[jcCURSOROUTLINE];
735 break;
736 case dvc(3):
737 color = jwin_pal[jcCURSORLIGHT];
738 break;
739 case dvc(5):
740 color = jwin_pal[jcCURSORDARK];
741 break;
742 default:
743 continue;
744 }
745 putpixel(bmp, x, y, color);
746 }
747 }
748 }
749 void load_mouse()
750 {
751 PALETTE pal;
752 BITMAP* cursor_bitmap = load_bitmap("assets/cursor.bmp", pal);
753 if (!cursor_bitmap)
754 Z_error_fatal("Missing required file %s\n", "assets/cursor.bmp");
755
756 enter_sys_pal();
757 MouseSprite::set(-1);
758 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
759 int32_t sz = 16*scale;
760 for(int32_t j = 0; j < 1; ++j)
761 {
762 BITMAP* tmpbmp = create_bitmap_ex(8,16,16);
763 if(zcmouse[j])
764 destroy_bitmap(zcmouse[j]);
765 zcmouse[j] = create_bitmap_ex(8,sz,sz);
766 clear_bitmap(zcmouse[j]);
767 clear_bitmap(tmpbmp);
768 blit(cursor_bitmap,tmpbmp,1,j*17+1,0,0,16,16);
769 recolor_mouse(tmpbmp);
770 if(sz!=16)
771 stretch_blit(tmpbmp, zcmouse[j], 0, 0, 16, 16, 0, 0, sz, sz);
772 else
773 blit(tmpbmp, zcmouse[j], 0, 0, 0, 0, 16, 16);
774 destroy_bitmap(tmpbmp);
775 }
776 if(!hw_palette) hw_palette = &RAMpal;
777 zc_set_palette(*hw_palette);
778
779 BITMAP* blankmouse = create_bitmap_ex(8,16,16);
780 clear_bitmap(blankmouse);
781
782 MouseSprite::assign(ZCM_NORMAL, zcmouse[0], 1*scale, 1*scale);
783 MouseSprite::assign(ZCM_BLANK, blankmouse);
784 //Don't assign ZCM_CUSTOM. That'll be handled by scripts.
785
786 //Reload the mouse
787 if(system_mouse)
788 sys_mouse();
789 else game_mouse();
790
791 destroy_bitmap(blankmouse);
792 destroy_bitmap(cursor_bitmap);
793 exit_sys_pal();
794 }
795
796 // sets the video mode and initializes the palette and mouse sprite
797 313 bool game_vid_mode(int32_t mode,int32_t wait)
798 {
799
1/2
✓ Branch 0 taken 313 times.
✗ Branch 1 not taken.
313 if (is_headless())
800 313 return true;
801
802 extern int zq_screen_w, zq_screen_h;
803 if(set_gfx_mode(mode,resx,resy,zq_screen_w,zq_screen_h)!=0)
804 {
805 return false;
806 }
807
808 scrx = (resx-320)>>1;
809 scry = (resy-240)>>1;
810 for(int32_t q = 0; q < NUM_ZCMOUSE; ++q)
811 zcmouse[q] = NULL;
812 load_mouse();
813
814 for(int32_t i=240; i<256; i++)
815 RAMpal[i]=pal_gui[i];
816
817 zc_set_palette(RAMpal);
818 clear_to_color(screen,BLACK);
819
820 rest(wait);
821 return true;
822 313 }
823
824 321 void null_quest()
825 {
826
1/2
✓ Branch 0 taken 321 times.
✗ Branch 1 not taken.
321 std::string title_assets_path = "modules/classic/title_gfx.dat";
827
2/4
✓ Branch 0 taken 321 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 321 times.
321 if (get_last_loaded_qstpath() == title_assets_path)
828 return;
829
830 byte skip_flags[4];
831
2/2
✓ Branch 0 taken 321 times.
✓ Branch 1 taken 8346 times.
8667 for (int i = 0; i < skip_max; i++)
832
1/2
✓ Branch 0 taken 8346 times.
✗ Branch 1 not taken.
8346 set_bit(skip_flags, i, 1);
833
1/2
✓ Branch 0 taken 321 times.
✗ Branch 1 not taken.
321 set_bit(skip_flags, skip_tiles, 0);
834
1/2
✓ Branch 0 taken 321 times.
✗ Branch 1 not taken.
321 set_bit(skip_flags, skip_csets, 0);
835
1/2
✓ Branch 0 taken 321 times.
✗ Branch 1 not taken.
321 set_bit(skip_flags, skip_misc, 0); // needed for miscsfx (skip this and `tests/replays/demons_inferno/demons_inferno_1_of_2.zplay` fails).
836
1/2
✓ Branch 0 taken 321 times.
✗ Branch 1 not taken.
321 loadquest(title_assets_path.c_str(), &QHeader, &QMisc, tunes+ZC_MIDI_COUNT, false, skip_flags, 0, false);
837 321 sfxdat = 1;
838 // TODO: sfx.dat is ~1.2 MB. Could be better to break that up into individual files and load on demand / not at startup.
839 // TODO: can we cache the tiles/colordata so we don't have to read title_gfx.dat more than once?
840 // colordata is tiny, but tilebuf is huge, so limit that to just what the title screen needs.
841 // Another option: embed this data into the binary (`xxd -i resources/modules/classic/title_gfx.dat > title_gfx.h`)
842
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 321 times.
321 }
843
844 321 void init_NES_mode()
845 {
846 321 null_quest();
847 321 }
848
849 //----------------------------------------------------------------
850
851 qword trianglelines[16]=
852 {
853 0x0000000000000000ULL,
854 0xFD00000000000000ULL,
855 0xFDFD000000000000ULL,
856 0xFDFDFD0000000000ULL,
857 0xFDFDFDFD00000000ULL,
858 0xFDFDFDFDFD000000ULL,
859 0xFDFDFDFDFDFD0000ULL,
860 0xFDFDFDFDFDFDFD00ULL,
861 0xFDFDFDFDFDFDFDFDULL,
862 0x00FDFDFDFDFDFDFDULL,
863 0x0000FDFDFDFDFDFDULL,
864 0x000000FDFDFDFDFDULL,
865 0x00000000FDFDFDFDULL,
866 0x0000000000FDFDFDULL,
867 0x000000000000FDFDULL,
868 0x00000000000000FDULL,
869 };
870
871 word screen_triangles[29][32];
872
873 // the ULL suffixes are to prevent this warning:
874 // warning: integer constant is too large for "int32_t" type
875
876 qword triangles[4][16][8]= //[direction][value][line]
877 {
878 {
879 {
880 0x0000000000000000ULL,
881 0x0000000000000000ULL,
882 0x0000000000000000ULL,
883 0x0000000000000000ULL,
884 0x0000000000000000ULL,
885 0x0000000000000000ULL,
886 0x0000000000000000ULL,
887 0x0000000000000000ULL
888 },
889 {
890 0xFD00000000000000ULL,
891 0x0000000000000000ULL,
892 0x0000000000000000ULL,
893 0x0000000000000000ULL,
894 0x0000000000000000ULL,
895 0x0000000000000000ULL,
896 0x0000000000000000ULL,
897 0x0000000000000000ULL
898 },
899 {
900 0xFDFD000000000000ULL,
901 0xFD00000000000000ULL,
902 0x0000000000000000ULL,
903 0x0000000000000000ULL,
904 0x0000000000000000ULL,
905 0x0000000000000000ULL,
906 0x0000000000000000ULL,
907 0x0000000000000000ULL
908 },
909 {
910 0xFDFDFD0000000000ULL,
911 0xFDFD000000000000ULL,
912 0xFD00000000000000ULL,
913 0x0000000000000000ULL,
914 0x0000000000000000ULL,
915 0x0000000000000000ULL,
916 0x0000000000000000ULL,
917 0x0000000000000000ULL
918 },
919 {
920 0xFDFDFDFD00000000ULL,
921 0xFDFDFD0000000000ULL,
922 0xFDFD000000000000ULL,
923 0xFD00000000000000ULL,
924 0x0000000000000000ULL,
925 0x0000000000000000ULL,
926 0x0000000000000000ULL,
927 0x0000000000000000ULL
928 },
929 {
930 0xFDFDFDFDFD000000ULL,
931 0xFDFDFDFD00000000ULL,
932 0xFDFDFD0000000000ULL,
933 0xFDFD000000000000ULL,
934 0xFD00000000000000ULL,
935 0x0000000000000000ULL,
936 0x0000000000000000ULL,
937 0x0000000000000000ULL
938 },
939 {
940 0xFDFDFDFDFDFD0000ULL,
941 0xFDFDFDFDFD000000ULL,
942 0xFDFDFDFD00000000ULL,
943 0xFDFDFD0000000000ULL,
944 0xFDFD000000000000ULL,
945 0xFD00000000000000ULL,
946 0x0000000000000000ULL,
947 0x0000000000000000ULL
948 },
949 {
950 0xFDFDFDFDFDFDFD00ULL,
951 0xFDFDFDFDFDFD0000ULL,
952 0xFDFDFDFDFD000000ULL,
953 0xFDFDFDFD00000000ULL,
954 0xFDFDFD0000000000ULL,
955 0xFDFD000000000000ULL,
956 0xFD00000000000000ULL,
957 0x0000000000000000ULL
958 },
959 {
960 0xFDFDFDFDFDFDFDFDULL,
961 0xFDFDFDFDFDFDFD00ULL,
962 0xFDFDFDFDFDFD0000ULL,
963 0xFDFDFDFDFD000000ULL,
964 0xFDFDFDFD00000000ULL,
965 0xFDFDFD0000000000ULL,
966 0xFDFD000000000000ULL,
967 0xFD00000000000000ULL
968 },
969 {
970 0xFDFDFDFDFDFDFDFDULL,
971 0xFDFDFDFDFDFDFDFDULL,
972 0xFDFDFDFDFDFDFD00ULL,
973 0xFDFDFDFDFDFD0000ULL,
974 0xFDFDFDFDFD000000ULL,
975 0xFDFDFDFD00000000ULL,
976 0xFDFDFD0000000000ULL,
977 0xFDFD000000000000ULL
978 },
979 {
980 0xFDFDFDFDFDFDFDFDULL,
981 0xFDFDFDFDFDFDFDFDULL,
982 0xFDFDFDFDFDFDFDFDULL,
983 0xFDFDFDFDFDFDFD00ULL,
984 0xFDFDFDFDFDFD0000ULL,
985 0xFDFDFDFDFD000000ULL,
986 0xFDFDFDFD00000000ULL,
987 0xFDFDFD0000000000ULL
988 },
989 {
990 0xFDFDFDFDFDFDFDFDULL,
991 0xFDFDFDFDFDFDFDFDULL,
992 0xFDFDFDFDFDFDFDFDULL,
993 0xFDFDFDFDFDFDFDFDULL,
994 0xFDFDFDFDFDFDFD00ULL,
995 0xFDFDFDFDFDFD0000ULL,
996 0xFDFDFDFDFD000000ULL,
997 0xFDFDFDFD00000000ULL
998 },
999 {
1000 0xFDFDFDFDFDFDFDFDULL,
1001 0xFDFDFDFDFDFDFDFDULL,
1002 0xFDFDFDFDFDFDFDFDULL,
1003 0xFDFDFDFDFDFDFDFDULL,
1004 0xFDFDFDFDFDFDFDFDULL,
1005 0xFDFDFDFDFDFDFD00ULL,
1006 0xFDFDFDFDFDFD0000ULL,
1007 0xFDFDFDFDFD000000ULL
1008 },
1009 {
1010 0xFDFDFDFDFDFDFDFDULL,
1011 0xFDFDFDFDFDFDFDFDULL,
1012 0xFDFDFDFDFDFDFDFDULL,
1013 0xFDFDFDFDFDFDFDFDULL,
1014 0xFDFDFDFDFDFDFDFDULL,
1015 0xFDFDFDFDFDFDFDFDULL,
1016 0xFDFDFDFDFDFDFD00ULL,
1017 0xFDFDFDFDFDFD0000ULL
1018 },
1019 {
1020 0xFDFDFDFDFDFDFDFDULL,
1021 0xFDFDFDFDFDFDFDFDULL,
1022 0xFDFDFDFDFDFDFDFDULL,
1023 0xFDFDFDFDFDFDFDFDULL,
1024 0xFDFDFDFDFDFDFDFDULL,
1025 0xFDFDFDFDFDFDFDFDULL,
1026 0xFDFDFDFDFDFDFDFDULL,
1027 0xFDFDFDFDFDFDFD00ULL
1028 },
1029 {
1030 0xFDFDFDFDFDFDFDFDULL,
1031 0xFDFDFDFDFDFDFDFDULL,
1032 0xFDFDFDFDFDFDFDFDULL,
1033 0xFDFDFDFDFDFDFDFDULL,
1034 0xFDFDFDFDFDFDFDFDULL,
1035 0xFDFDFDFDFDFDFDFDULL,
1036 0xFDFDFDFDFDFDFDFDULL,
1037 0xFDFDFDFDFDFDFDFDULL
1038 }
1039 },
1040 {
1041 {
1042 0x0000000000000000ULL,
1043 0x0000000000000000ULL,
1044 0x0000000000000000ULL,
1045 0x0000000000000000ULL,
1046 0x0000000000000000ULL,
1047 0x0000000000000000ULL,
1048 0x0000000000000000ULL,
1049 0x0000000000000000ULL
1050 },
1051 {
1052 0x00000000000000FDULL,
1053 0x0000000000000000ULL,
1054 0x0000000000000000ULL,
1055 0x0000000000000000ULL,
1056 0x0000000000000000ULL,
1057 0x0000000000000000ULL,
1058 0x0000000000000000ULL,
1059 0x0000000000000000ULL
1060 },
1061 {
1062 0x000000000000FDFDULL,
1063 0x00000000000000FDULL,
1064 0x0000000000000000ULL,
1065 0x0000000000000000ULL,
1066 0x0000000000000000ULL,
1067 0x0000000000000000ULL,
1068 0x0000000000000000ULL,
1069 0x0000000000000000ULL
1070 },
1071 {
1072 0x0000000000FDFDFDULL,
1073 0x000000000000FDFDULL,
1074 0x00000000000000FDULL,
1075 0x0000000000000000ULL,
1076 0x0000000000000000ULL,
1077 0x0000000000000000ULL,
1078 0x0000000000000000ULL,
1079 0x0000000000000000ULL
1080 },
1081 {
1082 0x00000000FDFDFDFDULL,
1083 0x0000000000FDFDFDULL,
1084 0x000000000000FDFDULL,
1085 0x00000000000000FDULL,
1086 0x0000000000000000ULL,
1087 0x0000000000000000ULL,
1088 0x0000000000000000ULL,
1089 0x0000000000000000ULL
1090 },
1091 {
1092 0x000000FDFDFDFDFDULL,
1093 0x00000000FDFDFDFDULL,
1094 0x0000000000FDFDFDULL,
1095 0x000000000000FDFDULL,
1096 0x00000000000000FDULL,
1097 0x0000000000000000ULL,
1098 0x0000000000000000ULL,
1099 0x0000000000000000ULL
1100 },
1101 {
1102 0x0000FDFDFDFDFDFDULL,
1103 0x000000FDFDFDFDFDULL,
1104 0x00000000FDFDFDFDULL,
1105 0x0000000000FDFDFDULL,
1106 0x000000000000FDFDULL,
1107 0x00000000000000FDULL,
1108 0x0000000000000000ULL,
1109 0x0000000000000000ULL
1110 },
1111 {
1112 0x00FDFDFDFDFDFDFDULL,
1113 0x0000FDFDFDFDFDFDULL,
1114 0x000000FDFDFDFDFDULL,
1115 0x00000000FDFDFDFDULL,
1116 0x0000000000FDFDFDULL,
1117 0x000000000000FDFDULL,
1118 0x00000000000000FDULL,
1119 0x0000000000000000ULL
1120 },
1121 {
1122 0xFDFDFDFDFDFDFDFDULL,
1123 0x00FDFDFDFDFDFDFDULL,
1124 0x0000FDFDFDFDFDFDULL,
1125 0x000000FDFDFDFDFDULL,
1126 0x00000000FDFDFDFDULL,
1127 0x0000000000FDFDFDULL,
1128 0x000000000000FDFDULL,
1129 0x00000000000000FDULL
1130 },
1131 {
1132 0xFDFDFDFDFDFDFDFDULL,
1133 0xFDFDFDFDFDFDFDFDULL,
1134 0x00FDFDFDFDFDFDFDULL,
1135 0x0000FDFDFDFDFDFDULL,
1136 0x000000FDFDFDFDFDULL,
1137 0x00000000FDFDFDFDULL,
1138 0x0000000000FDFDFDULL,
1139 0x000000000000FDFDULL
1140 },
1141 {
1142 0xFDFDFDFDFDFDFDFDULL,
1143 0xFDFDFDFDFDFDFDFDULL,
1144 0xFDFDFDFDFDFDFDFDULL,
1145 0x00FDFDFDFDFDFDFDULL,
1146 0x0000FDFDFDFDFDFDULL,
1147 0x000000FDFDFDFDFDULL,
1148 0x00000000FDFDFDFDULL,
1149 0x0000000000FDFDFDULL
1150 },
1151 {
1152 0xFDFDFDFDFDFDFDFDULL,
1153 0xFDFDFDFDFDFDFDFDULL,
1154 0xFDFDFDFDFDFDFDFDULL,
1155 0xFDFDFDFDFDFDFDFDULL,
1156 0x00FDFDFDFDFDFDFDULL,
1157 0x0000FDFDFDFDFDFDULL,
1158 0x000000FDFDFDFDFDULL,
1159 0x00000000FDFDFDFDULL
1160 },
1161 {
1162 0xFDFDFDFDFDFDFDFDULL,
1163 0xFDFDFDFDFDFDFDFDULL,
1164 0xFDFDFDFDFDFDFDFDULL,
1165 0xFDFDFDFDFDFDFDFDULL,
1166 0xFDFDFDFDFDFDFDFDULL,
1167 0x00FDFDFDFDFDFDFDULL,
1168 0x0000FDFDFDFDFDFDULL,
1169 0x000000FDFDFDFDFDULL
1170 },
1171 {
1172 0xFDFDFDFDFDFDFDFDULL,
1173 0xFDFDFDFDFDFDFDFDULL,
1174 0xFDFDFDFDFDFDFDFDULL,
1175 0xFDFDFDFDFDFDFDFDULL,
1176 0xFDFDFDFDFDFDFDFDULL,
1177 0xFDFDFDFDFDFDFDFDULL,
1178 0x00FDFDFDFDFDFDFDULL,
1179 0x0000FDFDFDFDFDFDULL
1180 },
1181 {
1182 0xFDFDFDFDFDFDFDFDULL,
1183 0xFDFDFDFDFDFDFDFDULL,
1184 0xFDFDFDFDFDFDFDFDULL,
1185 0xFDFDFDFDFDFDFDFDULL,
1186 0xFDFDFDFDFDFDFDFDULL,
1187 0xFDFDFDFDFDFDFDFDULL,
1188 0xFDFDFDFDFDFDFDFDULL,
1189 0x00FDFDFDFDFDFDFDULL
1190 },
1191 {
1192 0xFDFDFDFDFDFDFDFDULL,
1193 0xFDFDFDFDFDFDFDFDULL,
1194 0xFDFDFDFDFDFDFDFDULL,
1195 0xFDFDFDFDFDFDFDFDULL,
1196 0xFDFDFDFDFDFDFDFDULL,
1197 0xFDFDFDFDFDFDFDFDULL,
1198 0xFDFDFDFDFDFDFDFDULL,
1199 0xFDFDFDFDFDFDFDFDULL
1200 }
1201 },
1202 {
1203 {
1204 0x0000000000000000ULL,
1205 0x0000000000000000ULL,
1206 0x0000000000000000ULL,
1207 0x0000000000000000ULL,
1208 0x0000000000000000ULL,
1209 0x0000000000000000ULL,
1210 0x0000000000000000ULL,
1211 0x0000000000000000ULL
1212 },
1213 {
1214 0x0000000000000000ULL,
1215 0x0000000000000000ULL,
1216 0x0000000000000000ULL,
1217 0x0000000000000000ULL,
1218 0x0000000000000000ULL,
1219 0x0000000000000000ULL,
1220 0x0000000000000000ULL,
1221 0xFD00000000000000ULL
1222 },
1223 {
1224 0x0000000000000000ULL,
1225 0x0000000000000000ULL,
1226 0x0000000000000000ULL,
1227 0x0000000000000000ULL,
1228 0x0000000000000000ULL,
1229 0x0000000000000000ULL,
1230 0xFD00000000000000ULL,
1231 0xFDFD000000000000ULL
1232 },
1233 {
1234 0x0000000000000000ULL,
1235 0x0000000000000000ULL,
1236 0x0000000000000000ULL,
1237 0x0000000000000000ULL,
1238 0x0000000000000000ULL,
1239 0xFD00000000000000ULL,
1240 0xFDFD000000000000ULL,
1241 0xFDFDFD0000000000ULL
1242 },
1243 {
1244 0x0000000000000000ULL,
1245 0x0000000000000000ULL,
1246 0x0000000000000000ULL,
1247 0x0000000000000000ULL,
1248 0xFD00000000000000ULL,
1249 0xFDFD000000000000ULL,
1250 0xFDFDFD0000000000ULL,
1251 0xFDFDFDFD00000000ULL
1252 },
1253 {
1254 0x0000000000000000ULL,
1255 0x0000000000000000ULL,
1256 0x0000000000000000ULL,
1257 0xFD00000000000000ULL,
1258 0xFDFD000000000000ULL,
1259 0xFDFDFD0000000000ULL,
1260 0xFDFDFDFD00000000ULL,
1261 0xFDFDFDFDFD000000ULL
1262 },
1263 {
1264 0x0000000000000000ULL,
1265 0x0000000000000000ULL,
1266 0xFD00000000000000ULL,
1267 0xFDFD000000000000ULL,
1268 0xFDFDFD0000000000ULL,
1269 0xFDFDFDFD00000000ULL,
1270 0xFDFDFDFDFD000000ULL,
1271 0xFDFDFDFDFDFD0000ULL
1272 },
1273 {
1274 0x0000000000000000ULL,
1275 0xFD00000000000000ULL,
1276 0xFDFD000000000000ULL,
1277 0xFDFDFD0000000000ULL,
1278 0xFDFDFDFD00000000ULL,
1279 0xFDFDFDFDFD000000ULL,
1280 0xFDFDFDFDFDFD0000ULL,
1281 0xFDFDFDFDFDFDFD00ULL
1282 },
1283 {
1284 0xFD00000000000000ULL,
1285 0xFDFD000000000000ULL,
1286 0xFDFDFD0000000000ULL,
1287 0xFDFDFDFD00000000ULL,
1288 0xFDFDFDFDFD000000ULL,
1289 0xFDFDFDFDFDFD0000ULL,
1290 0xFDFDFDFDFDFDFD00ULL,
1291 0xFDFDFDFDFDFDFDFDULL
1292 },
1293 {
1294 0xFDFD000000000000ULL,
1295 0xFDFDFD0000000000ULL,
1296 0xFDFDFDFD00000000ULL,
1297 0xFDFDFDFDFD000000ULL,
1298 0xFDFDFDFDFDFD0000ULL,
1299 0xFDFDFDFDFDFDFD00ULL,
1300 0xFDFDFDFDFDFDFDFDULL,
1301 0xFDFDFDFDFDFDFDFDULL
1302 },
1303 {
1304 0xFDFDFD0000000000ULL,
1305 0xFDFDFDFD00000000ULL,
1306 0xFDFDFDFDFD000000ULL,
1307 0xFDFDFDFDFDFD0000ULL,
1308 0xFDFDFDFDFDFDFD00ULL,
1309 0xFDFDFDFDFDFDFDFDULL,
1310 0xFDFDFDFDFDFDFDFDULL,
1311 0xFDFDFDFDFDFDFDFDULL
1312 },
1313 {
1314 0xFDFDFDFD00000000ULL,
1315 0xFDFDFDFDFD000000ULL,
1316 0xFDFDFDFDFDFD0000ULL,
1317 0xFDFDFDFDFDFDFD00ULL,
1318 0xFDFDFDFDFDFDFDFDULL,
1319 0xFDFDFDFDFDFDFDFDULL,
1320 0xFDFDFDFDFDFDFDFDULL,
1321 0xFDFDFDFDFDFDFDFDULL
1322 },
1323 {
1324 0xFDFDFDFDFD000000ULL,
1325 0xFDFDFDFDFDFD0000ULL,
1326 0xFDFDFDFDFDFDFD00ULL,
1327 0xFDFDFDFDFDFDFDFDULL,
1328 0xFDFDFDFDFDFDFDFDULL,
1329 0xFDFDFDFDFDFDFDFDULL,
1330 0xFDFDFDFDFDFDFDFDULL,
1331 0xFDFDFDFDFDFDFDFDULL
1332 },
1333 {
1334 0xFDFDFDFDFDFD0000ULL,
1335 0xFDFDFDFDFDFDFD00ULL,
1336 0xFDFDFDFDFDFDFDFDULL,
1337 0xFDFDFDFDFDFDFDFDULL,
1338 0xFDFDFDFDFDFDFDFDULL,
1339 0xFDFDFDFDFDFDFDFDULL,
1340 0xFDFDFDFDFDFDFDFDULL,
1341 0xFDFDFDFDFDFDFDFDULL
1342 },
1343 {
1344 0xFDFDFDFDFDFDFD00ULL,
1345 0xFDFDFDFDFDFDFDFDULL,
1346 0xFDFDFDFDFDFDFDFDULL,
1347 0xFDFDFDFDFDFDFDFDULL,
1348 0xFDFDFDFDFDFDFDFDULL,
1349 0xFDFDFDFDFDFDFDFDULL,
1350 0xFDFDFDFDFDFDFDFDULL,
1351 0xFDFDFDFDFDFDFDFDULL
1352 },
1353 {
1354 0xFDFDFDFDFDFDFDFDULL,
1355 0xFDFDFDFDFDFDFDFDULL,
1356 0xFDFDFDFDFDFDFDFDULL,
1357 0xFDFDFDFDFDFDFDFDULL,
1358 0xFDFDFDFDFDFDFDFDULL,
1359 0xFDFDFDFDFDFDFDFDULL,
1360 0xFDFDFDFDFDFDFDFDULL,
1361 0xFDFDFDFDFDFDFDFDULL
1362 }
1363 },
1364 {
1365 {
1366 0x0000000000000000ULL,
1367 0x0000000000000000ULL,
1368 0x0000000000000000ULL,
1369 0x0000000000000000ULL,
1370 0x0000000000000000ULL,
1371 0x0000000000000000ULL,
1372 0x0000000000000000ULL,
1373 0x0000000000000000ULL
1374 },
1375 {
1376 0x0000000000000000ULL,
1377 0x0000000000000000ULL,
1378 0x0000000000000000ULL,
1379 0x0000000000000000ULL,
1380 0x0000000000000000ULL,
1381 0x0000000000000000ULL,
1382 0x0000000000000000ULL,
1383 0x00000000000000FDULL
1384 },
1385 {
1386 0x0000000000000000ULL,
1387 0x0000000000000000ULL,
1388 0x0000000000000000ULL,
1389 0x0000000000000000ULL,
1390 0x0000000000000000ULL,
1391 0x0000000000000000ULL,
1392 0x00000000000000FDULL,
1393 0x000000000000FDFDULL
1394 },
1395 {
1396 0x0000000000000000ULL,
1397 0x0000000000000000ULL,
1398 0x0000000000000000ULL,
1399 0x0000000000000000ULL,
1400 0x0000000000000000ULL,
1401 0x00000000000000FDULL,
1402 0x000000000000FDFDULL,
1403 0x0000000000FDFDFDULL
1404 },
1405 {
1406 0x0000000000000000ULL,
1407 0x0000000000000000ULL,
1408 0x0000000000000000ULL,
1409 0x0000000000000000ULL,
1410 0x00000000000000FDULL,
1411 0x000000000000FDFDULL,
1412 0x0000000000FDFDFDULL,
1413 0x00000000FDFDFDFDULL
1414 },
1415 {
1416 0x0000000000000000ULL,
1417 0x0000000000000000ULL,
1418 0x0000000000000000ULL,
1419 0x00000000000000FDULL,
1420 0x000000000000FDFDULL,
1421 0x0000000000FDFDFDULL,
1422 0x00000000FDFDFDFDULL,
1423 0x000000FDFDFDFDFDULL
1424 },
1425 {
1426 0x0000000000000000ULL,
1427 0x0000000000000000ULL,
1428 0x00000000000000FDULL,
1429 0x000000000000FDFDULL,
1430 0x0000000000FDFDFDULL,
1431 0x00000000FDFDFDFDULL,
1432 0x000000FDFDFDFDFDULL,
1433 0x0000FDFDFDFDFDFDULL
1434 },
1435 {
1436 0x0000000000000000ULL,
1437 0x00000000000000FDULL,
1438 0x000000000000FDFDULL,
1439 0x0000000000FDFDFDULL,
1440 0x00000000FDFDFDFDULL,
1441 0x000000FDFDFDFDFDULL,
1442 0x0000FDFDFDFDFDFDULL,
1443 0x00FDFDFDFDFDFDFDULL
1444 },
1445 {
1446 0x00000000000000FDULL,
1447 0x000000000000FDFDULL,
1448 0x0000000000FDFDFDULL,
1449 0x00000000FDFDFDFDULL,
1450 0x000000FDFDFDFDFDULL,
1451 0x0000FDFDFDFDFDFDULL,
1452 0x00FDFDFDFDFDFDFDULL,
1453 0xFDFDFDFDFDFDFDFDULL
1454 },
1455 {
1456 0x000000000000FDFDULL,
1457 0x0000000000FDFDFDULL,
1458 0x00000000FDFDFDFDULL,
1459 0x000000FDFDFDFDFDULL,
1460 0x0000FDFDFDFDFDFDULL,
1461 0x00FDFDFDFDFDFDFDULL,
1462 0xFDFDFDFDFDFDFDFDULL,
1463 0xFDFDFDFDFDFDFDFDULL
1464 },
1465 {
1466 0x0000000000FDFDFDULL,
1467 0x00000000FDFDFDFDULL,
1468 0x000000FDFDFDFDFDULL,
1469 0x0000FDFDFDFDFDFDULL,
1470 0x00FDFDFDFDFDFDFDULL,
1471 0xFDFDFDFDFDFDFDFDULL,
1472 0xFDFDFDFDFDFDFDFDULL,
1473 0xFDFDFDFDFDFDFDFDULL
1474 },
1475 {
1476 0x00000000FDFDFDFDULL,
1477 0x000000FDFDFDFDFDULL,
1478 0x0000FDFDFDFDFDFDULL,
1479 0x00FDFDFDFDFDFDFDULL,
1480 0xFDFDFDFDFDFDFDFDULL,
1481 0xFDFDFDFDFDFDFDFDULL,
1482 0xFDFDFDFDFDFDFDFDULL,
1483 0xFDFDFDFDFDFDFDFDULL
1484 },
1485 {
1486 0x000000FDFDFDFDFDULL,
1487 0x0000FDFDFDFDFDFDULL,
1488 0x00FDFDFDFDFDFDFDULL,
1489 0xFDFDFDFDFDFDFDFDULL,
1490 0xFDFDFDFDFDFDFDFDULL,
1491 0xFDFDFDFDFDFDFDFDULL,
1492 0xFDFDFDFDFDFDFDFDULL,
1493 0xFDFDFDFDFDFDFDFDULL
1494 },
1495 {
1496 0x0000FDFDFDFDFDFDULL,
1497 0x00FDFDFDFDFDFDFDULL,
1498 0xFDFDFDFDFDFDFDFDULL,
1499 0xFDFDFDFDFDFDFDFDULL,
1500 0xFDFDFDFDFDFDFDFDULL,
1501 0xFDFDFDFDFDFDFDFDULL,
1502 0xFDFDFDFDFDFDFDFDULL,
1503 0xFDFDFDFDFDFDFDFDULL
1504 },
1505 {
1506 0x00FDFDFDFDFDFDFDULL,
1507 0xFDFDFDFDFDFDFDFDULL,
1508 0xFDFDFDFDFDFDFDFDULL,
1509 0xFDFDFDFDFDFDFDFDULL,
1510 0xFDFDFDFDFDFDFDFDULL,
1511 0xFDFDFDFDFDFDFDFDULL,
1512 0xFDFDFDFDFDFDFDFDULL,
1513 0xFDFDFDFDFDFDFDFDULL
1514 },
1515 {
1516 0xFDFDFDFDFDFDFDFDULL,
1517 0xFDFDFDFDFDFDFDFDULL,
1518 0xFDFDFDFDFDFDFDFDULL,
1519 0xFDFDFDFDFDFDFDFDULL,
1520 0xFDFDFDFDFDFDFDFDULL,
1521 0xFDFDFDFDFDFDFDFDULL,
1522 0xFDFDFDFDFDFDFDFDULL,
1523 0xFDFDFDFDFDFDFDFDULL
1524 }
1525 }
1526 };
1527
1528 static bool is_opening_screen;
1529 int32_t black_opening_count=0;
1530 int32_t black_opening_x,black_opening_y;
1531 int32_t black_opening_shape;
1532
1533 3282 int32_t choose_opening_shape()
1534 {
1535 // First, count how many bits are set
1536 3282 int32_t numBits=0;
1537 int32_t bitCounter;
1538
1539
2/2
✓ Branch 0 taken 16410 times.
✓ Branch 1 taken 3282 times.
19692 for(int32_t i=0; i<bosMAX; i++)
1540 {
1541
2/2
✓ Branch 0 taken 12912 times.
✓ Branch 1 taken 3498 times.
16410 if(COOLSCROLL&(1<<i))
1542 3498 numBits++;
1543 16410 }
1544
1545 // Shouldn't happen...
1546
1/2
✓ Branch 0 taken 3282 times.
✗ Branch 1 not taken.
3282 if(numBits==0)
1547 return bosCIRCLE;
1548
1549 // Pick a bit
1550 3282 bitCounter=zc_rand()%numBits+1;
1551
1552
2/2
✓ Branch 0 taken 4476 times.
✓ Branch 1 taken 26 times.
4502 for(int32_t i=0; i<bosMAX; i++)
1553 {
1554 // If this bit is set, decrement the bit counter
1555
2/2
✓ Branch 0 taken 1064 times.
✓ Branch 1 taken 3412 times.
4476 if(COOLSCROLL&(1<<i))
1556 3412 bitCounter--;
1557
1558 // When the counter hits 0, return a value based on
1559 // which bit it stopped on.
1560 // Reminder: enum {bosCIRCLE=0, bosOVAL, bosTRIANGLE, bosSMAS, bosFADEBLACK, bosMAX};
1561
2/2
✓ Branch 0 taken 3256 times.
✓ Branch 1 taken 1220 times.
4476 if(bitCounter==0)
1562 3256 return i;
1563 1220 }
1564
1565 // Shouldn't be necessary, but the compiler might complain, at least
1566 26 return bosCIRCLE;
1567 3282 }
1568
1569 739 void close_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1570 {
1571 739 x -= viewport.x;
1572 739 y -= viewport.y;
1573
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 729 times.
739 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1574
1575 739 int32_t w=framebuf->w, h=framebuf->h;
1576 739 int32_t blockrows=h/8, blockcolumns=32;
1577 739 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1578
1579
2/2
✓ Branch 0 taken 20692 times.
✓ Branch 1 taken 739 times.
21431 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1580 {
1581
2/2
✓ Branch 0 taken 662144 times.
✓ Branch 1 taken 20692 times.
682836 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1582 {
1583
2/2
✓ Branch 0 taken 273677 times.
✓ Branch 1 taken 388467 times.
662144 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1584 662144 }
1585 20692 }
1586
1587 739 black_opening_count = 66;
1588 739 black_opening_x = x;
1589 739 black_opening_y = y;
1590 739 lensclk = 0;
1591 //black_opening_shape=(black_opening_shape+1)%bosMAX;
1592
1593
1594
1/2
✓ Branch 0 taken 739 times.
✗ Branch 1 not taken.
739 if(black_opening_shape == bosFADEBLACK)
1595 {
1596 refreshTints();
1597 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1598 }
1599
2/2
✓ Branch 0 taken 725 times.
✓ Branch 1 taken 14 times.
739 if(wait)
1600 {
1601 14 FFCore.warpScriptCheck();
1602
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 924 times.
938 for(int32_t i=0; i<66; i++)
1603 {
1604 924 draw_screen();
1605 924 advanceframe(true);
1606
1607
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 924 times.
924 if(Quit)
1608 {
1609 break;
1610 }
1611 924 }
1612 14 }
1613 739 }
1614
1615 2563 void open_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1616 {
1617 2563 x -= viewport.x;
1618 2563 y -= viewport.y;
1619
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2553 times.
2563 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1620
1621 2563 int32_t w=framebuf->w, h=framebuf->h;
1622 2563 int32_t blockrows=h/8, blockcolumns=32;
1623 2563 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1624
1625
2/2
✓ Branch 0 taken 71876 times.
✓ Branch 1 taken 2563 times.
74439 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1626 {
1627
2/2
✓ Branch 0 taken 2300032 times.
✓ Branch 1 taken 71876 times.
2371908 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1628 {
1629
2/2
✓ Branch 0 taken 1133766 times.
✓ Branch 1 taken 1166266 times.
2300032 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1630 2300032 }
1631 71876 }
1632
1633 2563 black_opening_count = -66;
1634 2563 black_opening_x = x;
1635 2563 black_opening_y = y;
1636 2563 lensclk = 0;
1637
1/2
✓ Branch 0 taken 2563 times.
✗ Branch 1 not taken.
2563 if(black_opening_shape == bosFADEBLACK)
1638 {
1639 refreshTints();
1640 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1641 }
1642
2/2
✓ Branch 0 taken 361 times.
✓ Branch 1 taken 2202 times.
2563 if(wait)
1643 {
1644 2202 FFCore.warpScriptCheck();
1645
2/2
✓ Branch 0 taken 2201 times.
✓ Branch 1 taken 145343 times.
147544 for(int32_t i=0; i<66; i++)
1646 {
1647 145343 draw_screen();
1648 145343 advanceframe(true);
1649
1650
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 145342 times.
145343 if(Quit)
1651 {
1652 1 break;
1653 }
1654 145342 }
1655 2202 }
1656 2563 }
1657
1658 217619 void black_opening(BITMAP *dest,int32_t x,int32_t y,int32_t a,int32_t max_a)
1659 {
1660 217619 clear_to_color(tmp_scr,BLACK);
1661 217619 int32_t w=dest->w, h=dest->h;
1662
1663
4/6
✗ Branch 0 not taken.
✓ Branch 1 taken 9636 times.
✓ Branch 2 taken 1980 times.
✓ Branch 3 taken 20328 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 185675 times.
217619 switch(black_opening_shape)
1664 {
1665 case bosOVAL:
1666 {
1667 9636 double new_w=(w/2)+abs(w/2-x);
1668 9636 double new_h=(h/2)+abs(h/2-y);
1669 9636 double b=sqrt(((new_w*new_w)/4)+(new_h*new_h));
1670 9636 ellipsefill(tmp_scr,x,y,int32_t(2*a*b/max_a)/8*8,int32_t(a*b/max_a)/8*8,0);
1671 9636 break;
1672 }
1673
1674 case bosTRIANGLE:
1675 {
1676 1980 double new_w=(w/2)+abs(w/2-x);
1677 1980 double new_h=(h/2)+abs(h/2-y);
1678 1980 double r=a*(new_w*sqrt((double)3)+new_h)/max_a;
1679 1980 double P2= (PI/2);
1680 1980 double P23=(2*PI/3);
1681 1980 double P43=(4*PI/3);
1682 1980 double Pa= (-4*PI*a/(3*max_a));
1683 1980 double angle=P2+Pa;
1684 1980 double a0=angle;
1685 1980 double a2=angle+P23;
1686 1980 double a4=angle+P43;
1687 3960 triangle(tmp_scr, x+int32_t(zc::math::Cos(a0)*r), y-int32_t(zc::math::Sin(a0)*r),
1688 1980 x+int32_t(zc::math::Cos(a2)*r), y-int32_t(zc::math::Sin(a2)*r),
1689 1980 x+int32_t(zc::math::Cos(a4)*r), y-int32_t(zc::math::Sin(a4)*r),
1690 0);
1691 1980 break;
1692 }
1693
1694 case bosSMAS:
1695 {
1696
2/2
✓ Branch 0 taken 7260 times.
✓ Branch 1 taken 13068 times.
20328 int32_t distance=zc_max(abs(w/2-x),abs(h/2-y))/8;
1697
1698
2/2
✓ Branch 0 taken 569184 times.
✓ Branch 1 taken 20328 times.
589512 for(int32_t blockrow=0; blockrow<h/8; ++blockrow) //30
1699 {
1700
2/2
✓ Branch 0 taken 4553472 times.
✓ Branch 1 taken 569184 times.
5122656 for(int32_t linerow=0; linerow<8; ++linerow)
1701 {
1702 4553472 qword *triangleline=(qword*)(tmp_scr->line[(blockrow*8+linerow)]);
1703
1704
2/2
✓ Branch 0 taken 145711104 times.
✓ Branch 1 taken 4553472 times.
150264576 for(int32_t blockcolumn=0; blockcolumn<32; ++blockcolumn) //40
1705 {
1706 437133312 *triangleline=triangles[(screen_triangles[blockrow][blockcolumn]&0xC000)>>14]
1707
6/6
✓ Branch 0 taken 105268072 times.
✓ Branch 1 taken 40443032 times.
✓ Branch 2 taken 96140976 times.
✓ Branch 3 taken 49570128 times.
✓ Branch 4 taken 55697944 times.
✓ Branch 5 taken 40443032 times.
145711104 [zc_min(zc_max((((31+distance)*(max_a-a)/max_a)+((screen_triangles[blockrow][blockcolumn]&0x0FFF)-0x0100)-(15+distance)),0),15)]
1708 145711104 [linerow];
1709 145711104 ++triangleline;
1710 145711104 }
1711 4553472 }
1712 569184 }
1713
1714 20328 break;
1715 }
1716
1717 case bosFADEBLACK:
1718 {
1719 if(black_opening_count<0)
1720 {
1721 black_fade(zc_min(-black_opening_count,63));
1722 }
1723 else if(black_opening_count>0)
1724 {
1725 black_fade(63-zc_max(black_opening_count-3,0));
1726 }
1727 else black_fade(0);
1728 return; //no blitting from tmp_scr!
1729 }
1730
1731 185675 case bosCIRCLE:
1732 default:
1733 {
1734 185675 double new_w=(w/2)+abs(w/2-x);
1735 185675 double new_h=(h/2)+abs(h/2-y);
1736 185675 int32_t r=int32_t(sqrt((new_w*new_w)+(new_h*new_h))*a/max_a);
1737 //circlefill(tmp_scr,x,y,a<<3,0);
1738 185675 circlefill(tmp_scr,x,y,r,0);
1739 185675 break;
1740 }
1741 }
1742
1743 217619 masked_blit(tmp_scr,dest,0,0,0,0,320,240);
1744 217619 }
1745
1746 // fadeamnt is 0-63
1747 void black_fade(int32_t fadeamnt)
1748 {
1749 fadeamnt = _rgb_scale_6[fadeamnt];
1750 for(int32_t i=0; i < 0xEF; i++)
1751 {
1752 RAMpal[i].r = vbound(tempblackpal[i].r-fadeamnt,0,255);
1753 RAMpal[i].g = vbound(tempblackpal[i].g-fadeamnt,0,255);
1754 RAMpal[i].b = vbound(tempblackpal[i].b-fadeamnt,0,255);
1755 }
1756
1757 refreshpal = true;
1758 }
1759
1760 //----------------------------------------------------------------
1761
1762 201552057 bool item_disabled(int32_t item) //is this item disabled?
1763 {
1764
2/2
✓ Branch 0 taken 14531591 times.
✓ Branch 1 taken 187020466 times.
201552057 return (unsigned(item) < MAXITEMS && game->items_off[item] != 0);
1765 }
1766
1767 15644362 bool can_use_item(int32_t item_type, int32_t item) //can Hero use this item?
1768 {
1769
2/2
✓ Branch 0 taken 254624 times.
✓ Branch 1 taken 15389738 times.
15644362 if(current_item(item_type, true) >=item)
1770 {
1771 254624 return true;
1772 }
1773
1774 15389738 return false;
1775 15644362 }
1776
1777 43606786 bool has_item(int32_t item_type, int32_t it) //does Hero possess this item?
1778 {
1779
5/9
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 4421290 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 337472 times.
✓ Branch 6 taken 28752509 times.
✓ Branch 7 taken 9900449 times.
✓ Branch 8 taken 195066 times.
43606786 switch(item_type)
1780 {
1781 case itype_bomb:
1782 case itype_sbomb:
1783 {
1784 int32_t itemid = getItemID(itemsbuf, item_type, it);
1785
1786 if(itemid == -1)
1787 return false;
1788
1789 return (game->get_item(itemid));
1790 }
1791
1792 case itype_clock:
1793 {
1794 4421290 int32_t itemid = getItemID(itemsbuf, item_type, it);
1795
1796
2/4
✓ Branch 0 taken 4421290 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4421290 times.
✗ Branch 3 not taken.
4421290 if(itemid != -1 && (itemsbuf[itemid].flags & item_flag1)) //Active clock
1797 return (game->get_item(itemid));
1798 4421290 return Hero.getClock()?1:0;
1799 }
1800
1801 case itype_key:
1802 return (game->get_keys()>0);
1803
1804 case itype_magiccontainer:
1805 return (game->get_maxmagic()>=game->get_mp_per_block());
1806
1807 case itype_triforcepiece: //it: -2=any, -1=current level, other=that level
1808 {
1809
1/3
✓ Branch 0 taken 337472 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
337472 switch(it)
1810 {
1811 case -2:
1812 {
1813 for(int32_t i=0; i<MAXLEVELS; i++)
1814 {
1815 if(game->lvlitems[i]&liTRIFORCE)
1816 {
1817 return true;
1818 }
1819 }
1820
1821 return false;
1822 }
1823
1824 case -1:
1825 return (game->lvlitems[dlevel]&liTRIFORCE);
1826
1827 default:
1828
2/4
✓ Branch 0 taken 337472 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 337472 times.
337472 if(it>=0&&it<MAXLEVELS)
1829 {
1830 337472 return (game->lvlitems[it]&liTRIFORCE);
1831 }
1832
1833 break;
1834 }
1835
1836 return 0;
1837 }
1838
1839 case itype_map: //it: -2=any, -1=current level, other=that level
1840 {
1841
2/3
✓ Branch 0 taken 541626 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28210883 times.
28752509 switch(it)
1842 {
1843 case -2:
1844 {
1845 for(int32_t i=0; i<MAXLEVELS; i++)
1846 {
1847 if(game->lvlitems[i]&liMAP)
1848 {
1849 return true;
1850 }
1851 }
1852
1853 return false;
1854 }
1855
1856 case -1:
1857 28210883 return (game->lvlitems[dlevel]&liMAP)!=0;
1858
1859 default:
1860
2/4
✓ Branch 0 taken 541626 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 541626 times.
541626 if(it>=0&&it<MAXLEVELS)
1861 {
1862 541626 return (game->lvlitems[it]&liMAP)!=0;
1863 }
1864
1865 break;
1866 }
1867
1868 return 0;
1869 }
1870
1871 case itype_compass: //it: -2=any, -1=current level, other=that level
1872 {
1873
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 9900449 times.
9900449 switch(it)
1874 {
1875 case -2:
1876 {
1877 for(int32_t i=0; i<MAXLEVELS; i++)
1878 {
1879 if(game->lvlitems[i]&liCOMPASS)
1880 {
1881 return true;
1882 }
1883 }
1884
1885 return false;
1886 }
1887
1888 case -1:
1889 9900449 return (game->lvlitems[dlevel]&liCOMPASS)!=0;
1890
1891 default:
1892 if(it>=0&&it<MAXLEVELS)
1893 {
1894 return (game->lvlitems[it]&liCOMPASS)!=0;
1895 }
1896
1897 break;
1898 }
1899 return 0;
1900 }
1901
1902 case itype_bosskey: //it: -2=any, -1=current level, other=that level
1903 {
1904
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 195066 times.
195066 switch(it)
1905 {
1906 case -2:
1907 {
1908 for(int32_t i=0; i<MAXLEVELS; i++)
1909 {
1910 if(game->lvlitems[i]&liBOSSKEY)
1911 {
1912 return true;
1913 }
1914 }
1915
1916 return false;
1917 }
1918
1919 case -1:
1920 195066 return (game->lvlitems[dlevel]&liBOSSKEY)?1:0;
1921
1922 default:
1923 if(it>=0&&it<MAXLEVELS)
1924 {
1925 return (game->lvlitems[it]&liBOSSKEY)?1:0;
1926 }
1927 break;
1928 }
1929 return 0;
1930 }
1931
1932 default:
1933 int32_t itemid = getItemID(itemsbuf, item_type, it);
1934
1935 if(itemid == -1)
1936 return false;
1937
1938 return game->get_item(itemid);
1939 }
1940 43606786 }
1941
1942 150981041 int current_item(int item_type, bool checkmagic, bool jinx_check, bool check_bunny)
1943 {
1944
9/9
✓ Branch 0 taken 4421290 times.
✓ Branch 1 taken 115610721 times.
✓ Branch 2 taken 4421290 times.
✓ Branch 3 taken 4421290 times.
✓ Branch 4 taken 4421290 times.
✓ Branch 5 taken 4421290 times.
✓ Branch 6 taken 4421290 times.
✓ Branch 7 taken 4421290 times.
✓ Branch 8 taken 4421290 times.
150981041 switch(item_type)
1945 {
1946 case itype_clock:
1947 {
1948 4421290 int maxid = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
1949
1950
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4421290 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4421290 if(maxid != -1 && (itemsbuf[maxid].flags & item_flag1)) //Active clock
1951 return itemsbuf[maxid].level;
1952
1953 4421290 return has_item(itype_clock,1) ? 1 : 0;
1954 }
1955
1956 case itype_key:
1957 4421290 return game->get_keys();
1958
1959 case itype_lkey:
1960 4421290 return game->lvlkeys[get_dlevel()];
1961
1962 case itype_magiccontainer:
1963 4421290 return game->get_maxmagic()/game->get_mp_per_block();
1964
1965 case itype_triforcepiece:
1966 {
1967 4421290 int count=0;
1968
1969
2/2
✓ Branch 0 taken 2263700480 times.
✓ Branch 1 taken 4421290 times.
2268121770 for(int i=0; i<MAXLEVELS; i++)
1970 {
1971 2263700480 count+=(game->lvlitems[i]&liTRIFORCE)?1:0;
1972 2263700480 }
1973
1974 4421290 return count;
1975 }
1976
1977 case itype_map:
1978 {
1979 4421290 int count=0;
1980
1981
2/2
✓ Branch 0 taken 2263700480 times.
✓ Branch 1 taken 4421290 times.
2268121770 for(int i=0; i<MAXLEVELS; i++)
1982 {
1983 2263700480 count+=(game->lvlitems[i]&liMAP)?1:0;
1984 2263700480 }
1985
1986 4421290 return count;
1987 }
1988
1989 case itype_compass:
1990 {
1991 4421290 int count=0;
1992
1993
2/2
✓ Branch 0 taken 2263700480 times.
✓ Branch 1 taken 4421290 times.
2268121770 for(int i=0; i<MAXLEVELS; i++)
1994 {
1995 2263700480 count+=(game->lvlitems[i]&liCOMPASS)?1:0;
1996 2263700480 }
1997
1998 4421290 return count;
1999 }
2000
2001 case itype_bosskey:
2002 {
2003 4421290 int count=0;
2004
2005
2/2
✓ Branch 0 taken 2263700480 times.
✓ Branch 1 taken 4421290 times.
2268121770 for(int i=0; i<MAXLEVELS; i++)
2006 {
2007 2263700480 count+=(game->lvlitems[i]&liBOSSKEY)?1:0;
2008 2263700480 }
2009
2010 4421290 return count;
2011 }
2012
2013 default:
2014 115610721 int maxid = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
2015
2016
2/2
✓ Branch 0 taken 81917743 times.
✓ Branch 1 taken 33692978 times.
115610721 if(maxid == -1)
2017 81917743 return 0;
2018
2019 33692978 return itemsbuf[maxid].level;
2020 }
2021 150981041 }
2022
2023 414 std::map<int32_t, int32_t> itemcache;
2024 414 std::map<int32_t, int32_t> itemcache_cost;
2025
2026 void removeFromItemCache(int32_t itemclass)
2027 {
2028 itemcache.erase(itemclass);
2029 itemcache_cost.erase(itemclass);
2030 cache_tile_mod_clear();
2031 }
2032
2033 13059050 void flushItemCache(bool justcost)
2034 {
2035 13059050 itemcache_cost.clear();
2036
2/2
✓ Branch 0 taken 12985420 times.
✓ Branch 1 taken 73630 times.
13059050 if(!justcost)
2037 73630 itemcache.clear();
2038
2/2
✓ Branch 0 taken 6357348 times.
✓ Branch 1 taken 6628072 times.
12985420 else if(replay_version_check(0,19))
2039 6357348 return;
2040
2041 6701702 cache_tile_mod_clear();
2042
2043 //also fix the active subscreen if items were deleted -DD
2044
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6701702 times.
6701702 if(game != NULL)
2045 {
2046 6701702 verifyBothWeapons();
2047 6701702 refresh_subscr_items();
2048 6701702 }
2049 13059050 }
2050
2051 // This is used often, so it should be as direct as possible.
2052 3070008012 int _c_item_id_internal(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2053 {
2054 3070008012 bool use_cost_cache = replay_version_check(19);
2055
2/2
✓ Branch 0 taken 2929876684 times.
✓ Branch 1 taken 140131328 times.
3070008012 if(jinx_check)
2056 {
2057 //special case for shields...
2058
3/4
✓ Branch 0 taken 54383156 times.
✓ Branch 1 taken 85748172 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 54383156 times.
140131328 if (itemtype == itype_shield && !HeroShieldClk())
2059 54383156 jinx_check = false;
2060
4/4
✓ Branch 0 taken 52645673 times.
✓ Branch 1 taken 33102499 times.
✓ Branch 2 taken 10990568 times.
✓ Branch 3 taken 41655105 times.
85748172 else if(!(HeroSwordClk() || HeroItemClk()))
2061 41655105 jinx_check = false; //not jinxed
2062 140131328 }
2063
4/4
✓ Branch 0 taken 125094 times.
✓ Branch 1 taken 3069882918 times.
✓ Branch 2 taken 1853 times.
✓ Branch 3 taken 123241 times.
3070008012 if(!Hero.BunnyClock() || itemtype == itype_pearl) // bunny_check does not apply
2064 3069884771 check_bunny = false;
2065
2/2
✓ Branch 0 taken 3012249416 times.
✓ Branch 1 taken 57758596 times.
3070008012 if(itemtype == itype_ring) checkmagic = true;
2066
4/4
✓ Branch 0 taken 3025914945 times.
✓ Branch 1 taken 44093067 times.
✓ Branch 2 taken 320798885 times.
✓ Branch 3 taken 25152461 times.
3415959358 if (!jinx_check && !check_bunny
2067
4/4
✓ Branch 0 taken 3025819312 times.
✓ Branch 1 taken 95633 times.
✓ Branch 2 taken 345951346 times.
✓ Branch 3 taken 2679867966 times.
3025914945 && (use_cost_cache || itemtype != itype_ring))
2068 {
2069
4/4
✓ Branch 0 taken 607185676 times.
✓ Branch 1 taken 2393481175 times.
✓ Branch 2 taken 270318411 times.
✓ Branch 3 taken 336867265 times.
3000666851 auto& cache = checkmagic && use_cost_cache ? itemcache_cost : itemcache;
2070 3000666851 auto res = cache.find(itemtype);
2071
2072
2/2
✓ Branch 0 taken 2849727357 times.
✓ Branch 1 taken 150939494 times.
3000666851 if(res != cache.end())
2073 2849727357 return res->second;
2074 150939494 }
2075
2076 220280655 int result = -1;
2077 220280655 int highestlevel = -1;
2078
2079
2/2
✓ Branch 0 taken 56391847680 times.
✓ Branch 1 taken 220280655 times.
56612128335 for(int i=0; i<MAXITEMS; i++)
2080 {
2081
6/6
✓ Branch 0 taken 6184727968 times.
✓ Branch 1 taken 50207119712 times.
✓ Branch 2 taken 96488169 times.
✓ Branch 3 taken 6088239799 times.
✓ Branch 4 taken 82048 times.
✓ Branch 5 taken 96406121 times.
56391847680 if(game->get_item(i) && itemsbuf[i].type==itemtype && !item_disabled(i))
2082 {
2083
4/4
✓ Branch 0 taken 91731626 times.
✓ Branch 1 taken 4674495 times.
✓ Branch 2 taken 2473305 times.
✓ Branch 3 taken 89258321 times.
96406121 if(checkmagic && itemtype != itype_magicring)
2084
2/2
✓ Branch 0 taken 89257620 times.
✓ Branch 1 taken 701 times.
89258321 if(!checkmagiccost(i))
2085 701 continue;
2086
6/6
✓ Branch 0 taken 88805441 times.
✓ Branch 1 taken 7599979 times.
✓ Branch 2 taken 1257252 times.
✓ Branch 3 taken 6342727 times.
✓ Branch 4 taken 4147756 times.
✓ Branch 5 taken 3452223 times.
96405420 if(jinx_check && (usesSwordJinx(i) ? HeroSwordClk() : HeroItemClk()))
2087
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3452223 times.
3452223 if(!(itemsbuf[i].flags & item_jinx_immune))
2088 3452223 continue;
2089
3/4
✓ Branch 0 taken 100571 times.
✓ Branch 1 taken 92852626 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 100571 times.
92953197 if(check_bunny && !checkbunny(i))
2090 100571 continue;
2091
2092
2/2
✓ Branch 0 taken 8438993 times.
✓ Branch 1 taken 84413633 times.
92852626 if(itemsbuf[i].level >= highestlevel)
2093 {
2094 84413633 highestlevel = itemsbuf[i].level;
2095 84413633 result=i;
2096 84413633 }
2097 92852626 }
2098 56388294185 }
2099
2100
4/4
✓ Branch 0 taken 176187588 times.
✓ Branch 1 taken 44093067 times.
✓ Branch 2 taken 95633 times.
✓ Branch 3 taken 176091955 times.
220280655 if(!(jinx_check || check_bunny)) //Can't cache jinx_check/check_bunny
2101 {
2102
2/2
✓ Branch 0 taken 134323968 times.
✓ Branch 1 taken 41767987 times.
176091955 if (use_cost_cache)
2103 {
2104
2/2
✓ Branch 0 taken 118410431 times.
✓ Branch 1 taken 15913537 times.
134323968 if (!checkmagic)
2105 15913537 itemcache[itemtype] = result;
2106
6/6
✓ Branch 0 taken 15913537 times.
✓ Branch 1 taken 118410431 times.
✓ Branch 2 taken 688507 times.
✓ Branch 3 taken 15225030 times.
✓ Branch 4 taken 673546 times.
✓ Branch 5 taken 14961 times.
134323968 if (checkmagic || result < 0 || checkmagiccost(result))
2107 134309007 itemcache_cost[itemtype] = result;
2108 134323968 }
2109 else
2110 {
2111 41767987 itemcache[itemtype] = result;
2112 }
2113 176091955 }
2114 220280655 return result;
2115 3070008012 }
2116
2117 // 'jinx_check' indicates that the highest level item *immune to jinxes* should be returned.
2118 3043222822 int current_item_id(int itype, bool checkmagic, bool jinx_check, bool check_bunny)
2119 {
2120
3/4
✓ Branch 0 taken 3026417069 times.
✓ Branch 1 taken 16805753 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3026417069 times.
3043222822 if(itype < 0 || itype >= itype_max) return -1;
2121
1/2
✓ Branch 0 taken 3026417069 times.
✗ Branch 1 not taken.
3026417069 if(game->OverrideItems[itype] > -2)
2122 {
2123 auto ovid = game->OverrideItems[itype];
2124 if(ovid < 0 || ovid >= MAXITEMS)
2125 return -1;
2126 if(itemsbuf[ovid].type == itype)
2127 {
2128 if(itype == itype_magicring)
2129 checkmagic = false;
2130 else if(itype == itype_ring)
2131 checkmagic = true;
2132
2133 if(checkmagic && !checkmagiccost(ovid))
2134 return -1;
2135
2136 if (jinx_check && !checkitem_jinx(ovid))
2137 {
2138 return -1;
2139 }
2140 return ovid;
2141 }
2142 }
2143 3026417069 auto ret = _c_item_id_internal(itype,checkmagic,jinx_check,check_bunny);
2144
2/2
✓ Branch 0 taken 96540385 times.
✓ Branch 1 taken 2929876684 times.
3026417069 if(!jinx_check) //If not already a jinx-immune-only check...
2145 {
2146 //And the player IS jinxed...
2147
2/2
✓ Branch 0 taken 2886285741 times.
✓ Branch 1 taken 43590943 times.
2929876684 if(HeroIsJinxed())
2148 {
2149 //Then do a jinx-immune-only check here
2150 43590943 auto ret2 = _c_item_id_internal(itype,checkmagic,true,check_bunny);
2151 //And *IF IT FINDS A VALID ITEM*, return that one instead! -Em
2152 //Should NOT need a compat rule, as this should always return -1 in old quests.
2153
2/2
✓ Branch 0 taken 3266237 times.
✓ Branch 1 taken 40324706 times.
43590943 if(ret2 > -1) return ret2;
2154 40324706 }
2155 2926610447 }
2156 3023150832 return ret;
2157 3043222822 }
2158
2159 66324047 int current_item_power(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2160 {
2161 66324047 int result = current_item_id(itemtype, checkmagic, jinx_check, check_bunny);
2162
2/2
✓ Branch 0 taken 35516653 times.
✓ Branch 1 taken 30807394 times.
66324047 return (result<0) ? 0 : itemsbuf[result].power;
2163 }
2164
2165 26 int32_t heart_container_id()
2166 {
2167
1/2
✓ Branch 0 taken 754 times.
✗ Branch 1 not taken.
754 for(int32_t i=0; i<MAXITEMS; i++)
2168 {
2169
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 728 times.
754 if(itemsbuf[i].type == itype_heartcontainer)
2170 {
2171 26 return i;
2172 }
2173 728 }
2174 return -1;
2175 26 }
2176
2177 struct tilemod_cache_state_t
2178 {
2179
6/6
✓ Branch 0 taken 4420934 times.
✓ Branch 1 taken 8540300 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8540298 times.
✓ Branch 4 taken 354 times.
✓ Branch 5 taken 8539944 times.
21501534 bool operator==(const tilemod_cache_state_t&) const = default;
2180
2181 bool valid;
2182 bool bunny_clock;
2183 bool superman;
2184 int shield;
2185 };
2186 tilemod_cache_state_t tilemod_cache_state;
2187 int32_t tilemod_cache_value;
2188
2189 6703253 void cache_tile_mod_clear()
2190 {
2191 6703253 tilemod_cache_state = {false};
2192 6703253 }
2193
2194 12961234 int32_t item_tile_mod()
2195 {
2196 51844936 tilemod_cache_state_t state = {
2197 .valid = true,
2198 12961234 .bunny_clock = Hero.BunnyClock() != 0,
2199 12961234 .superman = Hero.superman,
2200 12961234 .shield = Hero.active_shield_id,
2201 };
2202
2/2
✓ Branch 0 taken 8539944 times.
✓ Branch 1 taken 4421290 times.
12961234 if (tilemod_cache_state == state)
2203 8539944 return tilemod_cache_value;
2204
2205 4421290 int32_t tile=0;
2206 4421290 bool check_bombcost = !get_qr(qr_BROKEN_BOMB_AMMO_COSTS);
2207
4/4
✓ Branch 0 taken 4007992 times.
✓ Branch 1 taken 413298 times.
✓ Branch 2 taken 3079194 times.
✓ Branch 3 taken 928798 times.
4421290 if(check_bombcost || game->get_bombs())
2208 {
2209 3492492 int32_t itemid = current_item_id(itype_bomb,check_bombcost);
2210
3/4
✓ Branch 0 taken 3432971 times.
✓ Branch 1 taken 59521 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3432971 times.
3492492 if(itemid > -1 && checkbunny(itemid))
2211 3432971 tile+=itemsbuf[itemid].ltm;
2212 3492492 }
2213
2214
4/4
✓ Branch 0 taken 4007992 times.
✓ Branch 1 taken 413298 times.
✓ Branch 2 taken 965298 times.
✓ Branch 3 taken 3042694 times.
4421290 if(check_bombcost || game->get_sbombs())
2215 {
2216 1378596 int32_t itemid = current_item_id(itype_sbomb,check_bombcost);
2217
3/4
✓ Branch 0 taken 965057 times.
✓ Branch 1 taken 413539 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 965057 times.
1378596 if(itemid > -1 && checkbunny(itemid))
2218 965057 tile+=itemsbuf[itemid].ltm;
2219 1378596 }
2220
2221
2/2
✓ Branch 0 taken 4408554 times.
✓ Branch 1 taken 12736 times.
4421290 if(current_item(itype_clock))
2222 {
2223 12736 int32_t itemid =
2224
2/2
✓ Branch 0 taken 12704 times.
✓ Branch 1 taken 32 times.
12736 get_qr(qr_HARDCODED_LITEM_LTMS)
2225 ? iClock
2226 32 : getHighestLevelEvenUnowned(itemsbuf, itype_clock);
2227
2/4
✓ Branch 0 taken 12736 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12736 times.
12736 if(itemid > -1 && checkbunny(itemid))
2228 12736 tile+=itemsbuf[itemid].ltm;
2229 12736 }
2230
2231
2/2
✓ Branch 0 taken 3775648 times.
✓ Branch 1 taken 645642 times.
4421290 if(current_item(itype_key))
2232 {
2233 645642 int32_t itemid =
2234
2/2
✓ Branch 0 taken 608640 times.
✓ Branch 1 taken 37002 times.
645642 get_qr(qr_HARDCODED_LITEM_LTMS)
2235 ? iKey
2236 37002 : getHighestLevelEvenUnowned(itemsbuf, itype_key);
2237
2/4
✓ Branch 0 taken 645642 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 645642 times.
645642 if(itemid > -1 && checkbunny(itemid))
2238 645642 tile+=itemsbuf[itemid].ltm;
2239 645642 }
2240
2241
2/2
✓ Branch 0 taken 3920406 times.
✓ Branch 1 taken 500884 times.
4421290 if(current_item(itype_lkey))
2242 {
2243 500884 int32_t itemid =
2244
2/2
✓ Branch 0 taken 414169 times.
✓ Branch 1 taken 86715 times.
500884 get_qr(qr_HARDCODED_LITEM_LTMS)
2245 ? iLevelKey
2246 86715 : getHighestLevelEvenUnowned(itemsbuf, itype_lkey);
2247
2/4
✓ Branch 0 taken 500884 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 500884 times.
500884 if(itemid > -1 && checkbunny(itemid))
2248 500884 tile+=itemsbuf[itemid].ltm;
2249 500884 }
2250
2251
2/2
✓ Branch 0 taken 1586460 times.
✓ Branch 1 taken 2834830 times.
4421290 if(current_item(itype_map))
2252 {
2253 2834830 int32_t itemid =
2254
2/2
✓ Branch 0 taken 2823834 times.
✓ Branch 1 taken 10996 times.
2834830 get_qr(qr_HARDCODED_LITEM_LTMS)
2255 ? iMap
2256 10996 : getHighestLevelEvenUnowned(itemsbuf, itype_map);
2257
2/4
✓ Branch 0 taken 2834830 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2834830 times.
2834830 if(itemid > -1 && checkbunny(itemid))
2258 2834830 tile+=itemsbuf[itemid].ltm;
2259 2834830 }
2260
2261
2/2
✓ Branch 0 taken 2109301 times.
✓ Branch 1 taken 2311989 times.
4421290 if(current_item(itype_compass))
2262 {
2263 2311989 int32_t itemid =
2264
2/2
✓ Branch 0 taken 2295941 times.
✓ Branch 1 taken 16048 times.
2311989 get_qr(qr_HARDCODED_LITEM_LTMS)
2265 ? iCompass
2266 16048 : getHighestLevelEvenUnowned(itemsbuf, itype_compass);
2267
2/4
✓ Branch 0 taken 2311989 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2311989 times.
2311989 if(itemid > -1 && checkbunny(itemid))
2268 2311989 tile+=itemsbuf[itemid].ltm;
2269 2311989 }
2270
2271
2/2
✓ Branch 0 taken 1334874 times.
✓ Branch 1 taken 3086416 times.
4421290 if(current_item(itype_bosskey))
2272 {
2273 3086416 int32_t itemid =
2274
2/2
✓ Branch 0 taken 2993139 times.
✓ Branch 1 taken 93277 times.
3086416 get_qr(qr_HARDCODED_LITEM_LTMS)
2275 ? iBossKey
2276 93277 : getHighestLevelEvenUnowned(itemsbuf, itype_bosskey);
2277
2/4
✓ Branch 0 taken 3086416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3086416 times.
3086416 if(itemid > -1 && checkbunny(itemid))
2278 3086416 tile+=itemsbuf[itemid].ltm;
2279 3086416 }
2280
2281
2/2
✓ Branch 0 taken 48296 times.
✓ Branch 1 taken 4372994 times.
4421290 if(current_item(itype_magiccontainer))
2282 {
2283 4372994 int32_t itemid =
2284
2/2
✓ Branch 0 taken 3904336 times.
✓ Branch 1 taken 468658 times.
4372994 get_qr(qr_HARDCODED_LITEM_LTMS)
2285 ? iMagicC
2286 468658 : getHighestLevelEvenUnowned(itemsbuf, itype_magiccontainer);
2287
3/4
✓ Branch 0 taken 4372994 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 4372977 times.
4372994 if(itemid > -1 && checkbunny(itemid))
2288 4372977 tile+=itemsbuf[itemid].ltm;
2289 4372994 }
2290
2291
2/2
✓ Branch 0 taken 1314810 times.
✓ Branch 1 taken 3106480 times.
4421290 if(current_item(itype_triforcepiece))
2292 {
2293 3106480 int32_t itemid =
2294
2/2
✓ Branch 0 taken 3069478 times.
✓ Branch 1 taken 37002 times.
3106480 get_qr(qr_HARDCODED_LITEM_LTMS)
2295 ? iTriforce
2296 37002 : getHighestLevelEvenUnowned(itemsbuf, itype_triforcepiece);
2297
2/4
✓ Branch 0 taken 3106480 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3106480 times.
3106480 if(itemid > -1 && checkbunny(itemid))
2298 3106480 tile+=itemsbuf[itemid].ltm;
2299 3106480 }
2300
2301
2/2
✓ Branch 0 taken 2263700480 times.
✓ Branch 1 taken 4421290 times.
2268121770 for(int32_t i=0; i<itype_max; i++)
2302 {
2303
2/2
✓ Branch 0 taken 2023628800 times.
✓ Branch 1 taken 240071680 times.
2263700480 if(!get_qr(qr_HARDCODED_LITEM_LTMS))
2304 {
2305
2/2
✓ Branch 0 taken 4688900 times.
✓ Branch 1 taken 235382780 times.
240071680 switch(i)
2306 {
2307 case itype_bomb:
2308 case itype_sbomb:
2309 case itype_clock:
2310 case itype_key:
2311 case itype_lkey:
2312 case itype_map:
2313 case itype_compass:
2314 case itype_bosskey:
2315 case itype_magiccontainer:
2316 case itype_triforcepiece:
2317 4688900 continue; //already handled
2318 }
2319 235382780 }
2320 2259011580 int32_t itemid = current_item_id(i,false);
2321
2/2
✓ Branch 0 taken 2254590290 times.
✓ Branch 1 taken 4421290 times.
2259011580 if(i == itype_shield)
2322 4421290 itemid = getCurrentShield(false);
2323
2324
4/4
✓ Branch 0 taken 115677549 times.
✓ Branch 1 taken 2143334031 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 115677548 times.
2259011580 if(itemid < 0 || !checkbunny(itemid))
2325 2143334032 continue;
2326
2327 115677548 itemdata const& itm = itemsbuf[itemid];
2328
2329
2/2
✓ Branch 0 taken 111976845 times.
✓ Branch 1 taken 3700703 times.
115677548 switch(itm.type)
2330 {
2331 case itype_shield:
2332
1/2
✓ Branch 0 taken 3700703 times.
✗ Branch 1 not taken.
3700703 if(itm.flags & item_flag9) //active shield
2333 {
2334 if(!usingActiveShield(itemid))
2335 {
2336 tile+=itm.misc6; //'Inactive PTM'
2337 continue;
2338 }
2339 }
2340 3700703 break;
2341 }
2342
2343 115677548 tile+=itm.ltm;
2344 115677548 }
2345
2346 4421290 tilemod_cache_value = tile;
2347 4421290 tilemod_cache_state = state;
2348 4421290 return tile;
2349 12961234 }
2350
2351 12961234 int32_t bunny_tile_mod()
2352 {
2353
2/2
✓ Branch 0 taken 1870 times.
✓ Branch 1 taken 12959364 times.
12961234 if(Hero.BunnyClock())
2354 {
2355 1870 return game->get_bunny_ltm();
2356 }
2357 12959364 return 0;
2358 12961234 }
2359
2360 // Hints are drawn on a separate layer to combo reveals.
2361 // TODO: move out of zc_sys.cpp, weird place for this code.
2362 20058 void draw_lens_under(BITMAP *dest, bool layer)
2363 {
2364 //Lens flag 1: Replacement for qr_LENSHINTS; if set, lens will show hints. Does nothing if flag 2 is set.
2365 //Lens flag 2: Disable "hints", prevent rendering of Secret Combos
2366 //Lens flag 3: Don't show armos/chest/dive items
2367 //Lens flag 4: Show Raft Paths
2368 //Lens flag 5: Show Invisible Enemies
2369
4/4
✓ Branch 0 taken 19602 times.
✓ Branch 1 taken 456 times.
✓ Branch 2 taken 9801 times.
✓ Branch 3 taken 9801 times.
20058 bool hints = (itemsbuf[Hero.getLastLensID()].flags & item_flag2) ? false : (layer && (itemsbuf[Hero.getLastLensID()].flags & item_flag1));
2370
2371 20058 int32_t strike_hint_table[11]=
2372 {
2373 mfARROW, mfBOMB, mfBRANG, mfWANDMAGIC,
2374 mfSWORD, mfREFMAGIC, mfHOOKSHOT,
2375 mfREFFIREBALL, mfHAMMER, mfSWORDBEAM, mfWAND
2376 };
2377
2378 {
2379 20058 int32_t blink_rate=flash_reduction_enabled()?6:1;
2380 20058 int32_t tempitem, tempweapon=0;
2381 20058 strike_hint=strike_hint_table[strike_hint_counter];
2382
2383
2/2
✓ Branch 0 taken 19459 times.
✓ Branch 1 taken 599 times.
20058 if(strike_hint_timer>32)
2384 {
2385 599 strike_hint_timer=0;
2386 599 strike_hint_counter=((strike_hint_counter+1)%11);
2387 599 }
2388
2389 20058 ++strike_hint_timer;
2390
2391 3550266 for_every_visible_rpos_layer0([&](const rpos_handle_t& rpos_handle) {
2392 3530208 mapscr* scr = rpos_handle.scr;
2393 7306676 auto [x, y] = rpos_handle.xy();
2394 7060416 y += playing_field_offset;
2395
2396 3530208 int32_t tempitemx=-16, tempitemy=-16;
2397 3530208 int32_t tempweaponx=-16, tempweapony=-16;
2398
2399
2/2
✓ Branch 0 taken 7060416 times.
✓ Branch 1 taken 3530208 times.
10590624 for(int32_t iter=0; iter<2; ++iter)
2400 {
2401 7060416 int32_t checkflag=0;
2402
2403
2/2
✓ Branch 0 taken 3530208 times.
✓ Branch 1 taken 3530208 times.
7060416 if(iter==0)
2404 {
2405 3530208 checkflag = rpos_handle.cflag();
2406 3530208 }
2407 else
2408 {
2409 3530208 checkflag = rpos_handle.sflag();
2410 }
2411
2412
2/2
✓ Branch 0 taken 7059318 times.
✓ Branch 1 taken 1098 times.
7060416 if(checkflag==mfSTRIKE)
2413 {
2414
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 906 times.
1098 if(!hints)
2415 {
2416
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSTRIKE],scr->secretcset[sSTRIKE]);
2417 906 }
2418 else
2419 {
2420 192 checkflag = strike_hint;
2421 }
2422 1098 }
2423
2424
21/36
✓ Branch 0 taken 6911766 times.
✓ Branch 1 taken 3258 times.
✓ Branch 2 taken 108898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2602 times.
✓ Branch 5 taken 28750 times.
✓ Branch 6 taken 2418 times.
✓ Branch 7 taken 504 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 814 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 93 times.
✓ Branch 15 taken 96 times.
✓ Branch 16 taken 24 times.
✓ Branch 17 taken 25 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 138 times.
✓ Branch 21 taken 16 times.
✓ Branch 22 taken 16 times.
✓ Branch 23 taken 7 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 16 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 17 times.
✓ Branch 32 taken 35 times.
✓ Branch 33 taken 17 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 906 times.
7060416 switch(checkflag)
2425 {
2426 case 0:
2427 case mfZELDA:
2428 case mfPUSHED:
2429 case mfENEMY0:
2430 case mfENEMY1:
2431 case mfENEMY2:
2432 case mfENEMY3:
2433 case mfENEMY4:
2434 case mfENEMY5:
2435 case mfENEMY6:
2436 case mfENEMY7:
2437 case mfENEMY8:
2438 case mfENEMY9:
2439 case mfSINGLE:
2440 case mfSINGLE16:
2441 case mfNOENEMY:
2442 case mfTRAP_H:
2443 case mfTRAP_V:
2444 case mfTRAP_4:
2445 case mfTRAP_LR:
2446 case mfTRAP_UD:
2447 case mfNOGROUNDENEMY:
2448 case mfNOBLOCKS:
2449 case mfSCRIPT1:
2450 case mfSCRIPT2:
2451 case mfSCRIPT3:
2452 case mfSCRIPT4:
2453 case mfSCRIPT5:
2454 case mfSCRIPT6:
2455 case mfSCRIPT7:
2456 case mfSCRIPT8:
2457 case mfSCRIPT9:
2458 case mfSCRIPT10:
2459 case mfSCRIPT11:
2460 case mfSCRIPT12:
2461 case mfSCRIPT13:
2462 case mfSCRIPT14:
2463 case mfSCRIPT15:
2464 case mfSCRIPT16:
2465 case mfSCRIPT17:
2466 case mfSCRIPT18:
2467 case mfSCRIPT19:
2468 case mfSCRIPT20:
2469 case mfPITHOLE:
2470 case mfPITFALLFLOOR:
2471 case mfLAVA:
2472 case mfICE:
2473 case mfICEDAMAGE:
2474 case mfDAMAGE1:
2475 case mfDAMAGE2:
2476 case mfDAMAGE4:
2477 case mfDAMAGE8:
2478 case mfDAMAGE16:
2479 case mfDAMAGE32:
2480 case mfFREEZEALL:
2481 case mfFREZEALLANSFFCS:
2482 case mfFREEZEFFCSOLY:
2483 case mfSCRITPTW1TRIG:
2484 case mfSCRITPTW2TRIG:
2485 case mfSCRITPTW3TRIG:
2486 case mfSCRITPTW4TRIG:
2487 case mfSCRITPTW5TRIG:
2488 case mfSCRITPTW6TRIG:
2489 case mfSCRITPTW7TRIG:
2490 case mfSCRITPTW8TRIG:
2491 case mfSCRITPTW9TRIG:
2492 case mfSCRITPTW10TRIG:
2493 case mfTROWEL:
2494 case mfTROWELNEXT:
2495 case mfTROWELSPECIALITEM:
2496 case mfSLASHPOT:
2497 case mfLIFTPOT:
2498 case mfLIFTORSLASH:
2499 case mfLIFTROCK:
2500 case mfLIFTROCKHEAVY:
2501 case mfDROPITEM:
2502 case mfSPECIALITEM:
2503 case mfDROPKEY:
2504 case mfDROPLKEY:
2505 case mfDROPCOMPASS:
2506 case mfDROPMAP:
2507 case mfDROPBOSSKEY:
2508 case mfSPAWNNPC:
2509 case mfSWITCHHOOK:
2510 case mfSIDEVIEWLADDER:
2511 case mfSIDEVIEWPLATFORM:
2512 case mfNOENEMYSPAWN:
2513 case mfENEMYALL:
2514 case mfNOMIRROR:
2515 case mfUNSAFEGROUND:
2516 case mf168:
2517 case mf169:
2518 case mf170:
2519 case mf171:
2520 case mf172:
2521 case mf173:
2522 case mf174:
2523 case mf175:
2524 case mf176:
2525 case mf177:
2526 case mf178:
2527 case mf179:
2528 case mf180:
2529 case mf181:
2530 case mf182:
2531 case mf183:
2532 case mf184:
2533 case mf185:
2534 case mf186:
2535 case mf187:
2536 case mf188:
2537 case mf189:
2538 case mf190:
2539 case mf191:
2540 case mf192:
2541 case mf193:
2542 case mf194:
2543 case mf195:
2544 case mf196:
2545 case mf197:
2546 case mf198:
2547 case mf199:
2548 case mf200:
2549 case mf201:
2550 case mf202:
2551 case mf203:
2552 case mf204:
2553 case mf205:
2554 case mf206:
2555 case mf207:
2556 case mf208:
2557 case mf209:
2558 case mf210:
2559 case mf211:
2560 case mf212:
2561 case mf213:
2562 case mf214:
2563 case mf215:
2564 case mf216:
2565 case mf217:
2566 case mf218:
2567 case mf219:
2568 case mf220:
2569 case mf221:
2570 case mf222:
2571 case mf223:
2572 case mf224:
2573 case mf225:
2574 case mf226:
2575 case mf227:
2576 case mf228:
2577 case mf229:
2578 case mf230:
2579 case mf231:
2580 case mf232:
2581 case mf233:
2582 case mf234:
2583 case mf235:
2584 case mf236:
2585 case mf237:
2586 case mf238:
2587 case mf239:
2588 case mf240:
2589 case mf241:
2590 case mf242:
2591 case mf243:
2592 case mf244:
2593 case mf245:
2594 case mf246:
2595 case mf247:
2596 case mf248:
2597 case mf249:
2598 case mf250:
2599 case mf251:
2600 case mf252:
2601 case mf253:
2602 case mf254:
2603 case mfEXTENDED:
2604 6911766 break;
2605
2606 case mfPUSHUD:
2607 case mfPUSHLR:
2608 case mfPUSH4:
2609 case mfPUSHU:
2610 case mfPUSHD:
2611 case mfPUSHL:
2612 case mfPUSHR:
2613 case mfPUSHUDNS:
2614 case mfPUSHLRNS:
2615 case mfPUSH4NS:
2616 case mfPUSHUNS:
2617 case mfPUSHDNS:
2618 case mfPUSHLNS:
2619 case mfPUSHRNS:
2620 case mfPUSHUDINS:
2621 case mfPUSHLRINS:
2622 case mfPUSH4INS:
2623 case mfPUSHUINS:
2624 case mfPUSHDINS:
2625 case mfPUSHLINS:
2626 case mfPUSHRINS:
2627
3/4
✓ Branch 0 taken 1939 times.
✓ Branch 1 taken 1319 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1939 times.
3258 if(!hints && ((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&16))
2628
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1939 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1939 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1939 || ((get_debug() && zc_getkey(KEY_N)) && (frame&16))))
2629 {
2630 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->undercombo,scr->undercset);
2631 }
2632
2633
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3258 times.
3258 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2634
3/6
✓ Branch 0 taken 2520 times.
✓ Branch 1 taken 738 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 738 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
3258 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2635 {
2636
2/2
✓ Branch 0 taken 1488 times.
✓ Branch 1 taken 1032 times.
2520 if(hints)
2637 {
2638
3/3
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 63 times.
✓ Branch 2 taken 897 times.
1032 switch (rpos_handle.ctype())
2639 {
2640 case cPUSH_HEAVY:
2641 case cPUSH_HW:
2642 72 tempitem=getItemIDPower(itemsbuf,itype_bracelet,1);
2643 144 tempitemx=x, tempitemy=y;
2644
2645
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(tempitem>-1)
2646 72 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2647
2648 72 break;
2649
2650 case cPUSH_HEAVY2:
2651 case cPUSH_HW2:
2652 63 tempitem=getItemIDPower(itemsbuf,itype_bracelet,2);
2653 126 tempitemx=x, tempitemy=y;
2654
2655
1/2
✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
63 if(tempitem>-1)
2656 63 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2657
2658 63 break;
2659 }
2660 1032 }
2661 2520 }
2662
2663 3258 break;
2664
2665 case mfWHISTLE:
2666
1/2
✓ Branch 0 taken 2418 times.
✗ Branch 1 not taken.
2418 if(hints)
2667 {
2668 tempitem=getItemID(itemsbuf,itype_whistle,1);
2669
2670 if(tempitem<0) break;
2671
2672 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2673 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2674 {
2675 tempitemx=x;
2676 tempitemy=y;
2677 }
2678
2679 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2680 }
2681
2682 2418 break;
2683
2684 //Why is this here?
2685 case mfFAIRY:
2686 case mfMAGICFAIRY:
2687 case mfALLFAIRY:
2688 if(hints)
2689 {
2690 tempitem=getItemID(itemsbuf, itype_fairy,1);//iFairyMoving;
2691
2692 if(tempitem < 0) break;
2693
2694 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2695 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2696 {
2697 tempitemx=x;
2698 tempitemy=y;
2699 }
2700
2701 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2702 }
2703
2704 break;
2705
2706 case mfANYFIRE:
2707
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 252 times.
504 if(!hints)
2708 {
2709
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sBCANDLE],scr->secretcset[sBCANDLE]);
2710 252 }
2711 else
2712 {
2713 252 tempitem=getItemID(itemsbuf,itype_candle,1);
2714
2715
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(tempitem<0) break;
2716
2717
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2718
3/6
✓ Branch 0 taken 189 times.
✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 63 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
252 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2719 {
2720 189 tempitemx=x;
2721 189 tempitemy=y;
2722 189 }
2723
2724 252 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2725 }
2726
2727 504 break;
2728
2729 case mfSTRONGFIRE:
2730 if(!hints)
2731 {
2732 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sRCANDLE],scr->secretcset[sRCANDLE]);
2733 }
2734 else
2735 {
2736 tempitem=getItemID(itemsbuf,itype_candle,2);
2737
2738 if(tempitem<0) break;
2739
2740 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2741 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2742 {
2743 tempitemx=x;
2744 tempitemy=y;
2745 }
2746
2747 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2748 }
2749
2750 break;
2751
2752 case mfMAGICFIRE:
2753 if(!hints)
2754 {
2755 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWANDFIRE],scr->secretcset[sWANDFIRE]);
2756 }
2757 else
2758 {
2759 tempitem=getItemID(itemsbuf,itype_wand,1);
2760
2761 if(tempitem<0) break;
2762
2763 tempweapon=wFire;
2764
2765 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2766 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2767 {
2768 tempitemx=x;
2769 tempitemy=y;
2770 }
2771 else
2772 {
2773 tempweaponx=x;
2774 tempweapony=y;
2775 }
2776
2777 putweapon(dest,tempweaponx,tempweapony,tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2778 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2779 }
2780
2781 break;
2782
2783 case mfDIVINEFIRE:
2784 if(!hints)
2785 {
2786 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sDIVINEFIRE],scr->secretcset[sDIVINEFIRE]);
2787 }
2788 else
2789 {
2790 tempitem=getItemID(itemsbuf,itype_divinefire,1);
2791
2792 if(tempitem<0) break;
2793
2794 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2795 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2796 {
2797 tempitemx=x;
2798 tempitemy=y;
2799 }
2800
2801 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2802 }
2803
2804 break;
2805
2806 case mfARROW:
2807
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 732 times.
814 if(!hints)
2808 {
2809
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 732 times.
732 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sARROW],scr->secretcset[sARROW]);
2810 732 }
2811 else
2812 {
2813 82 tempitem=getItemID(itemsbuf,itype_arrow,1);
2814
2815
1/2
✓ Branch 0 taken 82 times.
✗ Branch 1 not taken.
82 if(tempitem<0) break;
2816
2817
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 82 times.
82 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2818
3/6
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
82 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2819 {
2820 61 tempitemx=x;
2821 61 tempitemy=y;
2822 61 }
2823
2824 82 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2825 }
2826
2827 814 break;
2828
2829 case mfSARROW:
2830 if(!hints)
2831 {
2832 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSARROW],scr->secretcset[sSARROW]);
2833 }
2834 else
2835 {
2836 tempitem=getItemID(itemsbuf,itype_arrow,2);
2837
2838 if(tempitem<0) break;
2839
2840 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2841 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2842 {
2843 tempitemx=x;
2844 tempitemy=y;
2845 }
2846
2847 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2848 }
2849
2850 break;
2851
2852 case mfGARROW:
2853 if(!hints)
2854 {
2855 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sGARROW],scr->secretcset[sGARROW]);
2856 }
2857 else
2858 {
2859 tempitem=getItemID(itemsbuf,itype_arrow,3);
2860
2861 if(tempitem<0) break;
2862
2863 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2864 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2865 {
2866 tempitemx=x;
2867 tempitemy=y;
2868 }
2869
2870 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2871 }
2872
2873 break;
2874
2875 case mfBOMB:
2876
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 76 times.
93 if(!hints)
2877 {
2878
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
76 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sBOMB],scr->secretcset[sBOMB]);
2879 76 }
2880 else
2881 {
2882 //tempitem=getItemID(itemsbuf,itype_bomb,1);
2883 17 tempweapon = wLitBomb;
2884
2885 //if (tempitem<0) break;
2886
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2887
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2888 {
2889 12 tempweaponx=x;
2890 12 tempweapony=y;
2891 12 }
2892
2893 17 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2894 }
2895
2896 93 break;
2897
2898 case mfSBOMB:
2899
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 48 times.
96 if(!hints)
2900 {
2901
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSBOMB],scr->secretcset[sSBOMB]);
2902 48 }
2903 else
2904 {
2905 //tempitem=getItemID(itemsbuf,itype_sbomb,1);
2906 //if (tempitem<0) break;
2907 48 tempweapon = wLitSBomb;
2908
2909
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2910
3/6
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2911 {
2912 36 tempweaponx=x;
2913 36 tempweapony=y;
2914 36 }
2915
2916 48 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2917 }
2918
2919 96 break;
2920
2921 case mfARMOS_SECRET:
2922
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 if(!hints)
2923 {
2924
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
2925 36 putcombo(dest,x,y,scr->secretcombo[sSTAIRS],scr->secretcset[sSTAIRS]);
2926 12 }
2927 24 break;
2928
2929 case mfBRANG:
2930
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 20 times.
25 if(!hints)
2931 {
2932
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
2933 60 putcombo(dest,x,y,scr->secretcombo[sBRANG],scr->secretcset[sBRANG]);
2934 20 }
2935 else
2936 {
2937 5 tempitem=getItemID(itemsbuf,itype_brang,1);
2938
2939
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(tempitem<0) break;
2940
2941
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2942
3/6
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
5 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2943 {
2944 4 tempitemx=x;
2945 4 tempitemy=y;
2946 4 }
2947
2948 5 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2949 }
2950
2951 25 break;
2952
2953 case mfMBRANG:
2954 if(!hints)
2955 {
2956 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMBRANG],scr->secretcset[sMBRANG]);
2957 }
2958 else
2959 {
2960 tempitem=getItemID(itemsbuf,itype_brang,2);
2961
2962 if(tempitem<0) break;
2963
2964 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2965 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2966 {
2967 tempitemx=x;
2968 tempitemy=y;
2969 }
2970
2971 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2972 }
2973
2974 break;
2975
2976 case mfFBRANG:
2977 if(!hints)
2978 {
2979 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sFBRANG],scr->secretcset[sFBRANG]);
2980 }
2981 else
2982 {
2983 tempitem=getItemID(itemsbuf,itype_brang,3);
2984
2985 if(tempitem<0) break;
2986
2987 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2988 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2989 {
2990 tempitemx=x;
2991 tempitemy=y;
2992 }
2993
2994 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2995 }
2996
2997 break;
2998
2999 case mfWANDMAGIC:
3000
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if(!hints)
3001 {
3002
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWANDMAGIC],scr->secretcset[sWANDMAGIC]);
3003 138 }
3004 else
3005 {
3006 tempitem=getItemID(itemsbuf,itype_wand,1);
3007
3008 if(tempitem<0) break;
3009
3010 tempweapon=itemsbuf[tempitem].wpn3;
3011
3012 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3013 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3014 {
3015 tempitemx=x;
3016 tempitemy=y;
3017 }
3018 else
3019 {
3020 tempweaponx=x;
3021 tempweapony=y;
3022 --lens_hint_weapon[wMagic][4];
3023
3024 if(lens_hint_weapon[wMagic][4]<-8)
3025 {
3026 lens_hint_weapon[wMagic][4]=8;
3027 }
3028 }
3029
3030 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3031 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3032 }
3033
3034 138 break;
3035
3036 case mfREFMAGIC:
3037
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3038 {
3039 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sREFMAGIC],scr->secretcset[sREFMAGIC]);
3040 }
3041 else
3042 {
3043 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3044
3045
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3046
3047 16 tempweapon=ewMagic;
3048
3049
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3050
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3051 {
3052 13 tempitemx=x;
3053 13 tempitemy=y;
3054 13 }
3055 else
3056 {
3057 3 tempweaponx=x;
3058 3 tempweapony=y;
3059
3060
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if(lens_hint_weapon[ewMagic][2]==up)
3061 {
3062 1 --lens_hint_weapon[ewMagic][4];
3063 1 }
3064 else
3065 {
3066 2 ++lens_hint_weapon[ewMagic][4];
3067 }
3068
3069
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(lens_hint_weapon[ewMagic][4]>8)
3070 {
3071 lens_hint_weapon[ewMagic][2]=up;
3072 }
3073
3074
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if(lens_hint_weapon[ewMagic][4]<=0)
3075 {
3076 2 lens_hint_weapon[ewMagic][2]=down;
3077 2 }
3078 }
3079
3080 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3081 16 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, lens_hint_weapon[ewMagic][2], lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3082 }
3083
3084 16 break;
3085
3086 case mfREFFIREBALL:
3087
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3088 {
3089 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sREFFIREBALL],scr->secretcset[sREFFIREBALL]);
3090 }
3091 else
3092 {
3093 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3094
3095
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3096
3097 16 tempweapon=ewFireball;
3098
3099
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3100
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3101 {
3102 12 tempitemx=x;
3103 12 tempitemy=y;
3104 12 tempweaponx=x;
3105 12 tempweapony=y;
3106 12 ++lens_hint_weapon[ewFireball][3];
3107
3108
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1 times.
12 if(lens_hint_weapon[ewFireball][3]>8)
3109 {
3110 1 lens_hint_weapon[ewFireball][3]=-8;
3111 1 lens_hint_weapon[ewFireball][4]=8;
3112 1 }
3113
3114
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
12 if(lens_hint_weapon[ewFireball][3]>0)
3115 {
3116 8 ++lens_hint_weapon[ewFireball][4];
3117 8 }
3118 else
3119 {
3120 4 --lens_hint_weapon[ewFireball][4];
3121 }
3122 12 }
3123
3124 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3125 16 putweapon(dest,tempweaponx+lens_hint_weapon[tempweapon][3],tempweapony+lens_hint_weapon[ewFireball][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3126 }
3127
3128 16 break;
3129
3130 case mfSWORD:
3131
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(!hints)
3132 {
3133 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSWORD],scr->secretcset[sSWORD]);
3134 }
3135 else
3136 {
3137 7 tempitem=getItemID(itemsbuf,itype_sword,1);
3138
3139
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(tempitem<0) break;
3140
3141
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3142
3/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
7 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3143 {
3144 5 tempitemx=x;
3145 5 tempitemy=y;
3146 5 }
3147
3148 7 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3149 }
3150
3151 7 break;
3152
3153 case mfWSWORD:
3154 if(!hints)
3155 {
3156 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWSWORD],scr->secretcset[sWSWORD]);
3157 }
3158 else
3159 {
3160 tempitem=getItemID(itemsbuf,itype_sword,2);
3161
3162 if(tempitem<0) break;
3163
3164 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3165 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3166 {
3167 tempitemx=x;
3168 tempitemy=y;
3169 }
3170
3171 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3172 }
3173
3174 break;
3175
3176 case mfMSWORD:
3177 if(!hints)
3178 {
3179 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMSWORD],scr->secretcset[sMSWORD]);
3180 }
3181 else
3182 {
3183 tempitem=getItemID(itemsbuf,itype_sword,3);
3184
3185 if(tempitem<0) break;
3186
3187 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3188 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3189 {
3190 tempitemx=x;
3191 tempitemy=y;
3192 }
3193
3194 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3195 }
3196
3197 break;
3198
3199 case mfXSWORD:
3200 if(!hints)
3201 {
3202 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sXSWORD],scr->secretcset[sXSWORD]);
3203 }
3204 else
3205 {
3206 tempitem=getItemID(itemsbuf,itype_sword,4);
3207
3208 if(tempitem<0) break;
3209
3210 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3211 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3212 {
3213 tempitemx=x;
3214 tempitemy=y;
3215 }
3216
3217 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3218 }
3219
3220 break;
3221
3222 case mfSWORDBEAM:
3223
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3224 {
3225 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSWORDBEAM],scr->secretcset[sSWORDBEAM]);
3226 }
3227 else
3228 {
3229 16 tempitem=getItemID(itemsbuf,itype_sword,1);
3230
3231
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3232
3233
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3234
3/6
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3235 {
3236 11 tempitemx=x;
3237 11 tempitemy=y;
3238 11 }
3239
3240 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 1);
3241 }
3242
3243 16 break;
3244
3245 case mfWSWORDBEAM:
3246 if(!hints)
3247 {
3248 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWSWORDBEAM],scr->secretcset[sWSWORDBEAM]);
3249 }
3250 else
3251 {
3252 tempitem=getItemID(itemsbuf,itype_sword,2);
3253
3254 if(tempitem<0) break;
3255
3256 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3257 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3258 {
3259 tempitemx=x;
3260 tempitemy=y;
3261 }
3262
3263 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 2);
3264 }
3265
3266 break;
3267
3268 case mfMSWORDBEAM:
3269 if(!hints)
3270 {
3271 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMSWORDBEAM],scr->secretcset[sMSWORDBEAM]);
3272 }
3273 else
3274 {
3275 tempitem=getItemID(itemsbuf,itype_sword,3);
3276
3277 if(tempitem<0) break;
3278
3279 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3280 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3281 {
3282 tempitemx=x;
3283 tempitemy=y;
3284 }
3285
3286 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 3);
3287 }
3288
3289 break;
3290
3291 case mfXSWORDBEAM:
3292 if(!hints)
3293 {
3294 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sXSWORDBEAM],scr->secretcset[sXSWORDBEAM]);
3295 }
3296 else
3297 {
3298 tempitem=getItemID(itemsbuf,itype_sword,4);
3299
3300 if(tempitem<0) break;
3301
3302 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3303 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3304 {
3305 tempitemx=x;
3306 tempitemy=y;
3307 }
3308
3309 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 4);
3310 }
3311
3312 break;
3313
3314 case mfHOOKSHOT:
3315
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3316 {
3317 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sHOOKSHOT],scr->secretcset[sHOOKSHOT]);
3318 }
3319 else
3320 {
3321 17 tempitem=getItemID(itemsbuf,itype_hookshot,1);
3322
3323
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3324
3325
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3326
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3327 {
3328 12 tempitemx=x;
3329 12 tempitemy=y;
3330 12 }
3331
3332 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3333 }
3334
3335 17 break;
3336
3337 case mfWAND:
3338
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(!hints)
3339 {
3340 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWAND],scr->secretcset[sWAND]);
3341 }
3342 else
3343 {
3344 35 tempitem=getItemID(itemsbuf,itype_wand,1);
3345
3346
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(tempitem<0) break;
3347
3348
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
35 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3349
3/6
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
35 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3350 {
3351 28 tempitemx=x;
3352 28 tempitemy=y;
3353 28 }
3354
3355 35 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3356 }
3357
3358 35 break;
3359
3360 case mfHAMMER:
3361
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3362 {
3363 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sHAMMER],scr->secretcset[sHAMMER]);
3364 }
3365 else
3366 {
3367 17 tempitem=getItemID(itemsbuf,itype_hammer,1);
3368
3369
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3370
3371
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3372
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3373 {
3374 13 tempitemx=x;
3375 13 tempitemy=y;
3376 13 }
3377
3378 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3379 }
3380
3381 17 break;
3382
3383 case mfARMOS_ITEM:
3384 case mfDIVE_ITEM:
3385 {
3386
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2602 times.
2602 int flag = (cur_screen < 128 && get_qr(qr_ITEMPICKUPSETSBELOW)) ? mITEM : mSPECIALITEM;
3387
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2602 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2602 times.
2602 if((!getmapflag(scr, flag) || (scr->flags9&fBELOWRETURN)) && !(itemsbuf[Hero.getLastLensID()].flags & item_flag3))
3388 {
3389 7806 putitem2(dest,x,y,scr->catchall, lens_hint_item[scr->catchall][0], lens_hint_item[scr->catchall][1], 0);
3390 2602 }
3391 2602 break;
3392 }
3393
3394 case 16:
3395 case 17:
3396 case 18:
3397 case 19:
3398 case 20:
3399 case 21:
3400 case 22:
3401 case 23:
3402 case 24:
3403 case 25:
3404 case 26:
3405 case 27:
3406 case 28:
3407 case 29:
3408 case 30:
3409 case 31:
3410
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 107890 times.
108898 if(!hints)
3411
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 107890 times.
215780 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3412 323670 putcombo(dest,x,y,scr->secretcombo[checkflag-16+4],scr->secretcset[checkflag-16+4]);
3413
3414 108898 break;
3415 case mfSECRETSNEXT:
3416 if(!hints)
3417 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3418 putcombo(dest,x,y,rpos_handle.data()+1,rpos_handle.cset());
3419
3420 break;
3421
3422 case mfSTRIKE:
3423
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3424 {
3425 906 goto special;
3426 }
3427 else
3428 {
3429 break;
3430 }
3431
3432 28750 default: goto special;
3433
3434 special:
3435
8/8
✓ Branch 0 taken 14732 times.
✓ Branch 1 taken 14924 times.
✓ Branch 2 taken 528 times.
✓ Branch 3 taken 14204 times.
✓ Branch 4 taken 496 times.
✓ Branch 5 taken 32 times.
✓ Branch 6 taken 6108 times.
✓ Branch 7 taken 8128 times.
29656 if(layer && ((checkflag!=mfRAFT && checkflag!=mfRAFT_BRANCH&& checkflag!=mfRAFT_BOUNCE) ||(itemsbuf[Hero.getLastLensID()].flags & item_flag4)))
3436 {
3437
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 6604 times.
✓ Branch 2 taken 4954 times.
✓ Branch 3 taken 1650 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1650 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6604 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate)) || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3438 {
3439 24770 rectfill(dest,x,y,x+15,y+15,WHITE);
3440 4954 }
3441 6604 }
3442
3443 29656 break;
3444 }
3445 7060416 }
3446 3530208 });
3447
3448 40116 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
3449 90824 auto [offx, offy] = translate_screen_coordinates_to_world(scr->screen);
3450
3451 40116 offx -= viewport.x;
3452 40116 offy -= viewport.y;
3453 40116 offy += playing_field_offset;
3454
3455
2/2
✓ Branch 0 taken 10029 times.
✓ Branch 1 taken 10029 times.
20058 if (layer)
3456 {
3457
2/2
✓ Branch 0 taken 9670 times.
✓ Branch 1 taken 359 times.
10029 if (scr->door[0]==dWALK)
3458 1795 rectfill(dest, 120+offx, 16+offy, 135+offx, 31+offy, WHITE);
3459
3460
2/2
✓ Branch 0 taken 9606 times.
✓ Branch 1 taken 423 times.
10029 if (scr->door[1]==dWALK)
3461 2115 rectfill(dest, 120+offx, 144+offy, 135+offx, 159+offy, WHITE);
3462
3463
2/2
✓ Branch 0 taken 9447 times.
✓ Branch 1 taken 582 times.
10029 if (scr->door[2]==dWALK)
3464 2910 rectfill(dest, 16+offx, 80+offy, 31+offx, 95+offy, WHITE);
3465
3466
2/2
✓ Branch 0 taken 9405 times.
✓ Branch 1 taken 624 times.
10029 if (scr->door[3]==dWALK)
3467 3120 rectfill(dest, 224+offx, 80+offy, 239+offx, 95+offy, WHITE);
3468
3469
2/2
✓ Branch 0 taken 9986 times.
✓ Branch 1 taken 43 times.
10029 if (scr->door[0]==dBOMB)
3470 {
3471 129 showbombeddoor(scr, dest, 0, offx, offy);
3472 43 }
3473
3474
2/2
✓ Branch 0 taken 9990 times.
✓ Branch 1 taken 39 times.
10029 if (scr->door[1]==dBOMB)
3475 {
3476 117 showbombeddoor(scr, dest, 1, offx, offy);
3477 39 }
3478
3479
2/2
✓ Branch 0 taken 10023 times.
✓ Branch 1 taken 6 times.
10029 if (scr->door[2]==dBOMB)
3480 {
3481 18 showbombeddoor(scr, dest, 2, offx, offy);
3482 6 }
3483
3484
2/2
✓ Branch 0 taken 9992 times.
✓ Branch 1 taken 37 times.
10029 if (scr->door[3]==dBOMB)
3485 {
3486 111 showbombeddoor(scr, dest, 3, offx, offy);
3487 37 }
3488 10029 }
3489
3490
3/4
✓ Branch 0 taken 18024 times.
✓ Branch 1 taken 2034 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18024 times.
20058 if (scr->stairx || scr->stairy)
3491 {
3492
2/2
✓ Branch 0 taken 911 times.
✓ Branch 1 taken 1123 times.
2034 if (!hints)
3493 {
3494
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1123 times.
1123 if (!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3495 3369 putcombo(dest,scr->stairx+offx,scr->stairy+offy,scr->secretcombo[sSTAIRS],scr->secretcset[sSTAIRS]);
3496 1123 }
3497 else
3498 {
3499
2/2
✓ Branch 0 taken 863 times.
✓ Branch 1 taken 48 times.
911 if(scr->flags&fWHISTLE)
3500 {
3501 48 tempitem=getItemID(itemsbuf,itype_whistle,1);
3502 48 int32_t tempitemx=-16+offx;
3503 48 int32_t tempitemy=-16+offy-playing_field_offset;
3504
3505
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if ((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&(blink_rate/4)))
3506
3/6
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&(blink_rate/4))))
3507 {
3508 48 tempitemx=scr->stairx+offx;
3509 48 tempitemy=scr->stairy+offy;
3510 24 }
3511
3512 48 putitem2(dest, tempitemx, tempitemy, tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3513 48 }
3514 }
3515 2034 }
3516 20058 });
3517 }
3518 20058 }
3519
3520 9690 void draw_lens_over()
3521 {
3522 9690 int w = 288;
3523 9690 int h = 240;
3524
3525
4/6
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9672 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
9690 static BITMAP *lens_scr = create_bitmap_ex(8,2*w,2*h);
3526 static int32_t last_width = -1;
3527 9690 int32_t width = itemsbuf[current_item_id(itype_lens,true)].misc1;
3528
3529 // Only redraw the circle if the size has changed
3530
2/2
✓ Branch 0 taken 9670 times.
✓ Branch 1 taken 20 times.
9690 if (width != last_width)
3531 {
3532 20 clear_to_color(lens_scr, BLACK);
3533 20 circlefill(lens_scr, w, h, width, 0);
3534 20 circle(lens_scr, w, h, width+2, 0);
3535 20 circle(lens_scr, w, h, width+5, 0);
3536 20 last_width=width;
3537 20 }
3538
3539 9690 masked_blit(lens_scr, framebuf, w-(HeroX()+8)+viewport.x, h-(HeroY()+8)+viewport.y, 0, playing_field_offset, 256, viewport.h);
3540 9690 do_primitives(framebuf, SPLAYER_LENS_OVER);
3541 9690 }
3542
3543 37074404 static void update_bmp_size(BITMAP** bmp_ptr, int w, int h)
3544 {
3545 37074404 BITMAP* bmp = *bmp_ptr;
3546
3/4
✓ Branch 0 taken 37074404 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37074398 times.
✓ Branch 3 taken 6 times.
37074404 if (bmp->w == w && bmp->h == h)
3547 37074398 return;
3548
3549 6 int depth = bitmap_color_depth(bmp);
3550 6 destroy_bitmap(bmp);
3551 6 *bmp_ptr = create_bitmap_ex(depth, w, h);
3552 37074404 }
3553
3554 32028 void draw_wavy(BITMAP *source, BITMAP *target, int32_t amplitude, bool interpol)
3555 {
3556
4/6
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 32022 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
32028 static BITMAP *wavebuf = create_bitmap_ex(8,288,240-original_playing_field_offset);
3557 32028 update_bmp_size(&wavebuf, 288, 240 - original_playing_field_offset);
3558
3559 32028 clear_to_color(wavebuf, BLACK);
3560 32028 blit(source,wavebuf,0,original_playing_field_offset,16,0,256,framebuf->h-original_playing_field_offset);
3561
3562 int32_t ofs;
3563
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32028 times.
32028 amplitude = zc_min(2048,amplitude); // some arbitrary limit to prevent crashing
3564
4/6
✓ Branch 0 taken 32028 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 32028 times.
✓ Branch 4 taken 606 times.
✓ Branch 5 taken 31422 times.
32028 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY)) amplitude = zc_min(16,amplitude);
3565 32028 int32_t amp2 = viewport.visible_height(show_bottom_8px);
3566
2/4
✓ Branch 0 taken 32028 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 32028 times.
32028 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY_2)) amp2*=2;
3567 32028 int32_t i=frame%amp2;
3568
3569
2/2
✓ Branch 0 taken 5382552 times.
✓ Branch 1 taken 32028 times.
5414580 for(int32_t j=0; j<viewport.visible_height(show_bottom_8px); j++)
3570 {
3571
3/4
✓ Branch 0 taken 2691276 times.
✓ Branch 1 taken 2691276 times.
✓ Branch 2 taken 2691276 times.
✗ Branch 3 not taken.
5382552 if(j&1 && interpol)
3572 {
3573 // Add 288*2048 to ensure it's never negative. It'll get modded out.
3574 ofs=288*2048+int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3575 }
3576 else
3577 {
3578 5382552 ofs=288*2048-int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3579 }
3580
3581
1/2
✓ Branch 0 taken 5382552 times.
✗ Branch 1 not taken.
5382552 if(ofs)
3582 {
3583
2/2
✓ Branch 0 taken 1377933312 times.
✓ Branch 1 taken 5382552 times.
1383315864 for(int32_t k=0; k<256; k++)
3584 {
3585 1377933312 target->line[j+original_playing_field_offset][k]=wavebuf->line[j][(k+ofs+16)%288];
3586 1377933312 }
3587 5382552 }
3588 5382552 }
3589 32028 }
3590
3591 28272 void draw_fuzzy(int32_t fuzz)
3592 // draws from right half of scrollbuf to framebuf
3593 {
3594 int32_t firstx, firsty, xstep, ystep, i, y, dx, dy;
3595 byte *start, *si, *di;
3596
3597
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28272 times.
28272 if(fuzz<1)
3598 fuzz = 1;
3599
3600 28272 xstep = 128%fuzz;
3601
3602
2/2
✓ Branch 0 taken 5890 times.
✓ Branch 1 taken 22382 times.
28272 if(xstep > 0)
3603 22382 xstep = fuzz-xstep;
3604
3605 28272 ystep = 112%fuzz;
3606
3607
2/2
✓ Branch 0 taken 8246 times.
✓ Branch 1 taken 20026 times.
28272 if(ystep > 0)
3608 20026 ystep = fuzz-ystep;
3609
3610 28272 firsty = 1;
3611
3612
2/2
✓ Branch 0 taken 28272 times.
✓ Branch 1 taken 1020148 times.
1048420 for(y=0; y<framebuf->h;)
3613 {
3614 1020148 start = &(scrollbuf_old->line[y][256]);
3615
3616
4/4
✓ Branch 0 taken 1006012 times.
✓ Branch 1 taken 6347064 times.
✓ Branch 2 taken 6332928 times.
✓ Branch 3 taken 1020148 times.
7353076 for(dy=0; dy<ystep && dy+y<framebuf->h; dy++)
3617 {
3618 6332928 si = start;
3619 6332928 di = &(framebuf->line[y+dy][0]);
3620 6332928 i = xstep;
3621 6332928 firstx = 1;
3622
3623
2/2
✓ Branch 0 taken 1621229568 times.
✓ Branch 1 taken 6332928 times.
1627562496 for(dx=0; dx<framebuf->w; dx++)
3624 {
3625 1621229568 *(di++) = *si;
3626
3627
2/2
✓ Branch 0 taken 1366065344 times.
✓ Branch 1 taken 255164224 times.
1621229568 if(++i >= fuzz)
3628 {
3629
2/2
✓ Branch 0 taken 248831296 times.
✓ Branch 1 taken 6332928 times.
255164224 if(!firstx)
3630 248831296 si += fuzz;
3631 else
3632 {
3633 6332928 si += fuzz-xstep;
3634 6332928 firstx = 0;
3635 }
3636
3637 255164224 i = 0;
3638 255164224 }
3639 1621229568 }
3640 6332928 }
3641
3642
2/2
✓ Branch 0 taken 991876 times.
✓ Branch 1 taken 28272 times.
1020148 if(!firsty)
3643 991876 y += fuzz;
3644 else
3645 {
3646 28272 y += ystep;
3647 28272 ystep = fuzz;
3648 28272 firsty = 0;
3649 }
3650 }
3651 28272 }
3652
3653 18521188 void updatescr(bool allowwavy)
3654 {
3655
4/6
✓ Branch 0 taken 313 times.
✓ Branch 1 taken 18520875 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 313 times.
✓ Branch 4 taken 313 times.
✗ Branch 5 not taken.
18521188 static BITMAP *wavybuf = create_bitmap_ex(8, framebuf->w, framebuf->h);
3656
4/6
✓ Branch 0 taken 313 times.
✓ Branch 1 taken 18520875 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 313 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 313 times.
18521188 static BITMAP *panorama = create_bitmap_ex(8, framebuf->w, framebuf->h);
3657 18521188 update_bmp_size(&wavybuf, framebuf->w, framebuf->h);
3658 18521188 update_bmp_size(&panorama, framebuf->w, framebuf->h);
3659
3660
2/2
✓ Branch 0 taken 18493087 times.
✓ Branch 1 taken 28101 times.
18521188 if(toogam)
3661 {
3662 28101 textout_ex(framebuf,font,"no walls",8,216,1,-1);
3663 28101 }
3664
3665
1/2
✓ Branch 0 taken 18521188 times.
✗ Branch 1 not taken.
18521188 if(Showpal)
3666 dump_pal(framebuf);
3667
3668
2/2
✓ Branch 0 taken 18005506 times.
✓ Branch 1 taken 515682 times.
18521188 if(!Playing)
3669 515682 black_opening_count=0;
3670
3671
2/2
✓ Branch 0 taken 18352343 times.
✓ Branch 1 taken 168845 times.
18521188 if(black_opening_count<0) //shape is opening up
3672 {
3673 168845 black_opening(framebuf,black_opening_x,black_opening_y,(66+black_opening_count),66);
3674
3675
2/4
✓ Branch 0 taken 168845 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 168845 times.
168845 if(Advance||(!Paused))
3676 {
3677 168845 ++black_opening_count;
3678 168845 }
3679 168845 }
3680
2/2
✓ Branch 0 taken 18303569 times.
✓ Branch 1 taken 48774 times.
18352343 else if(black_opening_count>0) //shape is closing
3681 {
3682 48774 black_opening(framebuf,black_opening_x,black_opening_y,black_opening_count,66);
3683
3684
2/4
✓ Branch 0 taken 48774 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 48774 times.
48774 if(Advance||(!Paused))
3685 {
3686 48774 --black_opening_count;
3687 48774 }
3688 48774 }
3689
3690
3/4
✓ Branch 0 taken 18306866 times.
✓ Branch 1 taken 214322 times.
✓ Branch 2 taken 18306866 times.
✗ Branch 3 not taken.
18521188 if(black_opening_count==0&&black_opening_shape==bosFADEBLACK)
3691 {
3692 black_opening_shape = bosCIRCLE;
3693 memcpy(RAMpal, tempblackpal, PAL_SIZE*sizeof(RGB));
3694 refreshTints();
3695 refreshpal=true;
3696 }
3697
3698
2/2
✓ Branch 0 taken 17888204 times.
✓ Branch 1 taken 632984 times.
18521188 if(refreshpal)
3699 {
3700 632984 refreshpal=false;
3701 632984 RAMpal[253] = _RGB(0,0,0);
3702 632984 RAMpal[254] = _RGB(255,255,255);
3703 632984 hw_palette = &RAMpal;
3704 632984 update_hw_pal = true;
3705 632984 refresh_rgb_tables();
3706 632984 }
3707
3708 18521188 bool clearwavy = (wavy <= 0);
3709
3710
2/2
✓ Branch 0 taken 8572 times.
✓ Branch 1 taken 18512616 times.
18521188 if(wavy <= 0)
3711 {
3712 // So far one thing can alter wavy apart from scripts: Wavy DMaps.
3713 18512616 wavy = (DMaps[cur_dmap].flags&dmfWAVY ? 4 : 0);
3714 18512616 }
3715
3716 18521188 blit(framebuf, wavybuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
3717
3718
6/6
✓ Branch 0 taken 32278 times.
✓ Branch 1 taken 18488910 times.
✓ Branch 2 taken 32156 times.
✓ Branch 3 taken 122 times.
✓ Branch 4 taken 128 times.
✓ Branch 5 taken 32028 times.
18521188 if(wavy && Playing && allowwavy)
3719 {
3720 32028 draw_wavy(framebuf, wavybuf, wavy,false);
3721 32028 }
3722
3723
2/2
✓ Branch 0 taken 18512616 times.
✓ Branch 1 taken 8572 times.
18521188 if(clearwavy)
3724 18512616 wavy = 0; // Wavy was set by a DMap flag. Clear it.
3725
2/4
✓ Branch 0 taken 8572 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8572 times.
8572 else if(Playing && !Paused)
3726 8572 wavy--; // Wavy was set by a script. Decrement it.
3727
3728
3/4
✓ Branch 0 taken 18005506 times.
✓ Branch 1 taken 515682 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18005506 times.
18521188 if(Playing && !Paused)
3729 18005506 ++light_wave_clk;
3730
3731
6/6
✓ Branch 0 taken 18005506 times.
✓ Branch 1 taken 515682 times.
✓ Branch 2 taken 260252 times.
✓ Branch 3 taken 17745254 times.
✓ Branch 4 taken 18 times.
✓ Branch 5 taken 260234 times.
18521188 if(Playing && msg_active && !screenscrolling)
3732 {
3733
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 260167 times.
260234 if(!(msg_bg_display_buf->clip))
3734 260167 blit_msgstr_bg(framebuf,0,0,0,playing_field_offset,256,176);
3735
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 260167 times.
260234 if(!(msg_portrait_display_buf->clip))
3736 260167 blit_msgstr_prt(framebuf,0,0,0,playing_field_offset,256,176);
3737
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 260167 times.
260234 if(!(msg_txt_display_buf->clip))
3738 260167 blit_msgstr_fg(framebuf,0,0,0,playing_field_offset,256,176);
3739 260234 }
3740
3741
3/4
✓ Branch 0 taken 18521188 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18327463 times.
✓ Branch 3 taken 193725 times.
18521188 bool nosubscr = GameLoaded && no_subscreen() && !(hero_scr->flags3&fNOSUBSCROFFSET);
3742
3743
2/2
✓ Branch 0 taken 18332736 times.
✓ Branch 1 taken 188452 times.
18521188 if(nosubscr)
3744 {
3745 188452 clear_to_color(panorama, 0);
3746 188452 blit(wavybuf,panorama,0,playing_field_offset,0,playing_field_offset/2,256,framebuf->h-playing_field_offset);
3747 188452 }
3748
3749 //TODO: Optimize blit 'overcalls' -Gleeok
3750
2/2
✓ Branch 0 taken 188452 times.
✓ Branch 1 taken 18332736 times.
18521188 BITMAP *source = nosubscr ? panorama : wavybuf;
3751 18521188 blit(source, framebuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
3752
3753 18521188 update_hw_screen();
3754 18521188 }
3755
3756 //----------------------------------------------------------------
3757
3758 static PALETTE syspal;
3759 int32_t onGUISnapshot()
3760 {
3761 char buf[200];
3762 int32_t num=0;
3763 do
3764 {
3765 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3766 }
3767 while(num<99999 && exists(buf));
3768
3769 if (!al_save_bitmap(buf, al_get_backbuffer(all_get_display())))
3770 InfoDialog("Error", "Failed to save snapshot").show();
3771
3772 return D_O_K;
3773 }
3774
3775 int32_t onNonGUISnapshot()
3776 {
3777 PALETTE temppal;
3778 get_palette(temppal);
3779 bool realpal=(zc_getkey(KEY_ZC_LCONTROL, true) || zc_getkey(KEY_ZC_RCONTROL, true));
3780
3781 char buf[200];
3782 int32_t num=0;
3783
3784 do
3785 {
3786 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3787 }
3788 while(num<99999 && exists(buf));
3789
3790 if (no_subscreen() && !(hero_scr->flags3&fNOSUBSCROFFSET) && !key[KEY_ALT])
3791 {
3792 BITMAP *b = create_bitmap_ex(8, 256, viewport.visible_height(show_bottom_8px));
3793 clear_to_color(b,0);
3794 blit(framebuf,b,0,playing_field_offset/2,0,0,b->w,b->h);
3795 alleg4_save_bitmap(b, SnapshotScale, buf, realpal ? temppal : RAMpal);
3796 destroy_bitmap(b);
3797 }
3798 else
3799 {
3800 alleg4_save_bitmap(framebuf, SnapshotScale, buf, realpal?temppal:RAMpal);
3801 }
3802
3803 return D_O_K;
3804 }
3805
3806 int32_t onSnapshot()
3807 {
3808 if(zc_getkey(KEY_LSHIFT, true)||zc_getkey(KEY_RSHIFT, true))
3809 {
3810 onGUISnapshot();
3811 }
3812 else
3813 {
3814 onNonGUISnapshot();
3815 }
3816
3817 return D_O_K;
3818 }
3819
3820 int32_t onSaveMapPic()
3821 {
3822 char buf[200];
3823 int32_t num=0;
3824 BITMAP* _screen_draw_buffer = NULL;
3825 _screen_draw_buffer = create_bitmap_ex(8,256,176);
3826
3827 do
3828 {
3829 sprintf(buf, "%szc_screen%05d.png", get_snap_str(), ++num);
3830 }
3831 while(num<99999 && exists(buf));
3832
3833 BITMAP* mappic = create_bitmap_ex(8,(256*16),(176*8));
3834 clear_to_color(mappic, BLACK);
3835
3836 if(!mappic)
3837 {
3838 enter_sys_pal();
3839 jwin_alert("View Map","Not enough memory.",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
3840 exit_sys_pal();
3841 return D_O_K;;
3842 }
3843
3844 clear_to_color(_screen_draw_buffer, BLACK);
3845
3846 auto prev_viewport = viewport;
3847 viewport.x = 0;
3848 viewport.y = 0;
3849
3850 // draw the map
3851
3852 for(int32_t y=0; y<8; y++)
3853 {
3854 for(int32_t x=0; x<16; x++)
3855 {
3856 if (!displayOnMap(x, y))
3857 continue;
3858
3859 int screen = map_scr_xy_to_index(x, y);
3860 auto scrs = loadscr2(screen);
3861 mapscr* scr = &scrs[0];
3862 if (!scr->is_valid())
3863 continue;
3864
3865 screen_handles_t screen_handles;
3866 for (int i = 0; i <= 6; i++)
3867 screen_handles[i] = {scr, scrs[i].is_valid() ? &scrs[i] : nullptr, screen, i};
3868
3869 int xx = 0;
3870 int yy = -playing_field_offset;
3871
3872 if(XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3873 {
3874 do_layer(_screen_draw_buffer, 0, screen_handles[2], xx, yy);
3875 do_ffc_layer(_screen_draw_buffer, -2, screen_handles[0], xx, yy);
3876 }
3877
3878 if(XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
3879 {
3880 do_layer(_screen_draw_buffer, 0, screen_handles[3], xx, yy);
3881 do_ffc_layer(_screen_draw_buffer, -3, screen_handles[0], xx, yy);
3882 }
3883
3884 if(lenscheck(scr,0))
3885 putscr(scr, _screen_draw_buffer, 0, 0);
3886 do_ffc_layer(_screen_draw_buffer, 0, screen_handles[0], xx, yy);
3887 do_layer(_screen_draw_buffer, 0, screen_handles[1], xx, yy);
3888 do_ffc_layer(_screen_draw_buffer, 1, screen_handles[0], xx, yy);
3889
3890 if(!XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3891 {
3892 do_layer(_screen_draw_buffer, 0, screen_handles[2], xx, yy);
3893 do_ffc_layer(_screen_draw_buffer, 2, screen_handles[0], xx, yy);
3894 }
3895
3896 putscrdoors(scr, _screen_draw_buffer, xx, yy);
3897 if(get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
3898 {
3899 do_layer(_screen_draw_buffer, -2, screen_handles[0], xx, yy);
3900 if(get_qr(qr_PUSHBLOCK_LAYER_1_2))
3901 {
3902 do_layer(_screen_draw_buffer, -2, screen_handles[1], xx, yy);
3903 do_layer(_screen_draw_buffer, -2, screen_handles[2], xx, yy);
3904 }
3905 }
3906
3907 if(!XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
3908 {
3909 do_layer(_screen_draw_buffer, 0, screen_handles[3], xx, yy);
3910 do_ffc_layer(_screen_draw_buffer, 3, screen_handles[0], xx, yy);
3911 }
3912
3913 do_layer(_screen_draw_buffer, 0, screen_handles[4], xx, yy);
3914 do_ffc_layer(_screen_draw_buffer, 4, screen_handles[0], xx, yy);
3915 do_layer(_screen_draw_buffer, -1, screen_handles[0], xx, yy);
3916 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3917 {
3918 do_layer(_screen_draw_buffer, -1, screen_handles[1], xx, yy);
3919 do_layer(_screen_draw_buffer, -1, screen_handles[2], xx, yy);
3920 }
3921 do_layer(_screen_draw_buffer, 0, screen_handles[5], xx, yy);
3922 do_ffc_layer(_screen_draw_buffer, 5, screen_handles[0], xx, yy);
3923 if(replay_version_check(40))
3924 do_ffc_layer(_screen_draw_buffer, -1, screen_handles[0], xx, yy);
3925 do_layer(_screen_draw_buffer, 0, screen_handles[6], xx, yy);
3926 do_ffc_layer(_screen_draw_buffer, 6, screen_handles[0], xx, yy);
3927 do_ffc_layer(_screen_draw_buffer, 7, screen_handles[0], xx, yy);
3928
3929 blit(_screen_draw_buffer, mappic, 0, 0, x*256, y*176, 256, 176);
3930 }
3931 }
3932
3933 viewport = prev_viewport;
3934 save_bitmap(buf,mappic,RAMpal);
3935 destroy_bitmap(mappic);
3936 destroy_bitmap(_screen_draw_buffer);
3937 return D_O_K;
3938 }
3939
3940 46 void f_Quit(int32_t type)
3941 {
3942
2/4
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 46 times.
✗ Branch 3 not taken.
46 if(type==qQUIT && !Playing)
3943 return;
3944
3945 46 bool from_menu = is_sys_pal;
3946
3947
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(!from_menu)
3948 {
3949 46 music_pause();
3950 46 pause_all_sfx();
3951 46 sys_mouse();
3952 46 }
3953 46 enter_sys_pal();
3954 46 clear_keybuf();
3955
3956
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 13 times.
46 if (replay_version_check(0, 10))
3957 13 replay_poll();
3958
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if (replay_is_replaying())
3959 46 replay_peek_quit();
3960
3961
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 if (!replay_is_replaying())
3962 switch(type)
3963 {
3964 case qQUIT:
3965 onQuit();
3966 break;
3967
3968 case qRESET:
3969 onReset();
3970 break;
3971
3972 case qEXIT:
3973 onExit();
3974 break;
3975 }
3976
3977
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 if(Quit)
3978 {
3979 46 kill_sfx();
3980 46 music_stop();
3981 46 exit_sys_pal();
3982 46 update_hw_screen();
3983 46 }
3984 else
3985 {
3986 exit_sys_pal();
3987 if(!from_menu)
3988 {
3989 music_resume();
3990 resume_all_sfx();
3991 }
3992 }
3993
3994
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(!from_menu)
3995 46 game_mouse();
3996 46 eat_buttons();
3997
3998 46 zc_readrawkey(KEY_ESC);
3999
4000 46 zc_readrawkey(KEY_ENTER);
4001 46 }
4002
4003 //----------------------------------------------------------------
4004
4005 int32_t onNoWalls()
4006 {
4007 cheats_enqueue(Cheat::Walls);
4008 return D_O_K;
4009 }
4010
4011 int32_t onIgnoreSideview()
4012 {
4013 cheats_enqueue(Cheat::IgnoreSideView);
4014 return D_O_K;
4015 }
4016
4017 18519801 int32_t input_idle(bool checkmouse)
4018 {
4019 static int32_t mx, my, mz, mb;
4020
4021
4/6
✓ Branch 0 taken 18519801 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4960120 times.
✓ Branch 3 taken 13559681 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4960120 times.
23479921 if(keypressed() || zc_key_pressed() ||
4022
4/8
✓ Branch 0 taken 4960120 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4960120 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4960120 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4960120 times.
✗ Branch 7 not taken.
4960120 (checkmouse && (mx != mouse_x || my != mouse_y || mz != mouse_z || mb != mouse_b)))
4023 {
4024 13559681 idle_count = 0;
4025
4026
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13559681 times.
13559681 if(active_count < MAX_ACTIVE)
4027 {
4028 13559681 ++active_count;
4029 13559681 }
4030 13559681 }
4031
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4960120 times.
4960120 else if(idle_count < MAX_IDLE)
4032 {
4033 4960120 ++idle_count;
4034 4960120 active_count = 0;
4035 4960120 }
4036
4037 18519801 mx = mouse_x;
4038 18519801 my = mouse_y;
4039 18519801 mz = mouse_z;
4040 18519801 mb = mouse_b;
4041
4042 18519801 return idle_count;
4043 }
4044
4045 int32_t onGoFast()
4046 {
4047 cheats_enqueue(Cheat::Fast);
4048 return D_O_K;
4049 }
4050
4051 int32_t onKillCheat()
4052 {
4053 cheats_enqueue(Cheat::Kill);
4054 return D_O_K;
4055 }
4056
4057 int32_t onSecretsCheat()
4058 {
4059 cheats_enqueue(Cheat::TrigSecrets);
4060 return D_O_K;
4061 }
4062 int32_t onSecretsCheatPerm()
4063 {
4064 cheats_enqueue(Cheat::TrigSecretsPerm);
4065 return D_O_K;
4066 }
4067
4068 int32_t onShowLayer0()
4069 {
4070 show_layers[0] = !show_layers[0];
4071 return D_O_K;
4072 }
4073 int32_t onShowLayer1()
4074 {
4075 show_layers[1] = !show_layers[1];
4076 return D_O_K;
4077 }
4078 int32_t onShowLayer2()
4079 {
4080 show_layers[2] = !show_layers[2];
4081 return D_O_K;
4082 }
4083 int32_t onShowLayer3()
4084 {
4085 show_layers[3] = !show_layers[3];
4086 return D_O_K;
4087 }
4088 int32_t onShowLayer4()
4089 {
4090 show_layers[4] = !show_layers[4];
4091 return D_O_K;
4092 }
4093 int32_t onShowLayer5()
4094 {
4095 show_layers[5] = !show_layers[5];
4096 return D_O_K;
4097 }
4098 int32_t onShowLayer6()
4099 {
4100 show_layers[6] = !show_layers[6];
4101 return D_O_K;
4102 }
4103 int32_t onShowLayerO()
4104 {
4105 show_layer_over=!show_layer_over;
4106 return D_O_K;
4107 }
4108 int32_t onShowLayerP()
4109 {
4110 show_layer_push=!show_layer_push;
4111 return D_O_K;
4112 }
4113 int32_t onShowLayerS()
4114 {
4115 show_sprites=!show_sprites;
4116 return D_O_K;
4117 }
4118 int32_t onShowLayerF()
4119 {
4120 show_ffcs=!show_ffcs;
4121 return D_O_K;
4122 }
4123 int32_t onShowLayerW()
4124 {
4125 show_walkflags=!show_walkflags;
4126 if(show_walkflags)
4127 show_effectflags = false;
4128 return D_O_K;
4129 }
4130 int32_t onShowLayerE()
4131 {
4132 show_effectflags=!show_effectflags;
4133 if(show_effectflags)
4134 show_walkflags = false;
4135 return D_O_K;
4136 }
4137 int32_t onShowFFScripts()
4138 {
4139 show_ff_scripts=!show_ff_scripts;
4140 return D_O_K;
4141 }
4142 int32_t onShowHitboxes()
4143 {
4144 show_hitboxes=!show_hitboxes;
4145 return D_O_K;
4146 }
4147 int32_t onShowInfoOpacity()
4148 {
4149 info_opacity = vbound(getnumber("Debug Info Opacity",info_opacity),0,255);
4150 zc_set_config("zc","debug_info_opacity",info_opacity);
4151 return D_O_K;
4152 }
4153
4154 int32_t onLightSwitch()
4155 {
4156 cheats_enqueue(Cheat::Light);
4157 return D_O_K;
4158 }
4159
4160 int32_t onGoTo();
4161 int32_t onGoToComplete();
4162
4163 18519801 bool handle_close_btn_quit()
4164 {
4165
1/2
✓ Branch 0 taken 18519801 times.
✗ Branch 1 not taken.
18519801 if(close_button_quit)
4166 {
4167 close_button_quit=false;
4168 f_Quit(qEXIT);
4169 }
4170 18519801 return (exiting_program = Quit==qEXIT);
4171 }
4172
4173 18519801 void syskeys()
4174 {
4175 18519801 update_system_keys();
4176
4177 int32_t oldtitle_version;
4178
4179 18519801 poll_joystick();
4180
4181 18519801 handle_close_btn_quit();
4182
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18519801 times.
18519801 if(Quit == qEXIT) return;
4183
4184
2/10
✓ Branch 0 taken 18519801 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18519801 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
18519801 if(rMbtn() || (gui_mouse_b() && !mouse_down && ClickToFreeze &&!disableClickToFreeze))
4185 {
4186 System();
4187 }
4188
4189 18519801 mouse_down=gui_mouse_b();
4190
4191
1/2
✓ Branch 0 taken 18519801 times.
✗ Branch 1 not taken.
18519801 if(zc_read_system_key(KEY_F1))
4192 {
4193 if(zc_get_system_key(KEY_ZC_LCONTROL) || zc_get_system_key(KEY_ZC_RCONTROL))
4194 {
4195 halt=!halt;
4196 //zinit.subscreen=(zinit.subscreen+1)%ssdtMAX;
4197 }
4198 else
4199 {
4200 Throttlefps=!Throttlefps;
4201 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4202 }
4203 }
4204
4205
1/2
✓ Branch 0 taken 18519801 times.
✗ Branch 1 not taken.
18519801 if(zc_read_system_key(KEY_F2))
4206 {
4207 ShowFPS=!ShowFPS;
4208 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
4209 }
4210
4211
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18519801 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18519801 if(zc_read_system_key(KEY_F3) && Playing) Paused=!Paused;
4212
4213
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18519801 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18519801 if(zc_read_system_key(KEY_F4) && Playing)
4214 {
4215 Paused=true;
4216 Advance=true;
4217 }
4218
4219
1/2
✓ Branch 0 taken 18519801 times.
✗ Branch 1 not taken.
18519801 if(zc_read_system_key(KEY_F6)) onTryQuit();
4220
4221 #ifndef ALLEGRO_MACOSX
4222
1/2
✓ Branch 0 taken 18519801 times.
✗ Branch 1 not taken.
18519801 if(zc_read_system_key(KEY_F9)) f_Quit(qRESET);
4223
4224
1/2
✓ Branch 0 taken 18519801 times.
✗ Branch 1 not taken.
18519801 if(zc_read_system_key(KEY_F10)) f_Quit(qEXIT);
4225 #else
4226 if(zc_read_system_key(KEY_F7)) f_Quit(qRESET);
4227
4228 if(zc_read_system_key(KEY_F8)) f_Quit(qEXIT);
4229 #endif
4230
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 18519801 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
18519801 if(zc_read_system_key(KEY_F5)&&(Playing && cur_screen<128 && DMaps[cur_dmap].flags&dmfVIEWMAP)) onSaveMapPic();
4231
4232
1/2
✓ Branch 0 taken 18519801 times.
✗ Branch 1 not taken.
18519801 if (zc_read_system_key(KEY_F12))
4233 {
4234 onSnapshot();
4235 }
4236
4237
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18519801 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18519801 if(debug_enabled && zc_read_system_key(KEY_TAB))
4238 set_debug(!get_debug());
4239
4240
1/2
✓ Branch 0 taken 18519801 times.
✗ Branch 1 not taken.
18519801 if(CheatModifierKeys())
4241 {
4242 for(Cheat c = (Cheat)1; c < Cheat::Last; c = (Cheat)(c+1))
4243 {
4244 if(!bindable_cheat(c))
4245 continue;
4246 if(get_debug() || cheat >= cheat_lvl(c))
4247 {
4248 if(checkcheat(c))
4249 cheats_hit_bind(c);
4250 }
4251 }
4252 }
4253
4254
1/2
✓ Branch 0 taken 18519801 times.
✗ Branch 1 not taken.
18519801 if(volkeys)
4255 {
4256 if(zc_read_system_key(KEY_PGUP)) master_volume(-1,midi_volume+8);
4257
4258 if(zc_read_system_key(KEY_PGDN)) master_volume(-1,midi_volume==255?248:midi_volume-8);
4259
4260 if(zc_read_system_key(KEY_HOME)) master_volume(digi_volume+8,-1);
4261
4262 if(zc_read_system_key(KEY_END)) master_volume(digi_volume==255?248:digi_volume-8,-1);
4263 }
4264
4265
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 18519801 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
18519801 if(!get_debug() || !SystemKeys || replay_is_replaying())
4266 18519801 goto bottom;
4267
4268 if(zc_readkey(KEY_P)) Paused=!Paused;
4269
4270 if(zc_readkey(KEY_A))
4271 {
4272 Paused=true;
4273 Advance=true;
4274 }
4275
4276 if(zc_readkey(KEY_G)) db=(db==999)?0:999;
4277 #ifndef ALLEGRO_MACOSX
4278 if(zc_readkey(KEY_F8)) Showpal=!Showpal;
4279
4280 if(zc_readkey(KEY_F7))
4281 {
4282 Matrix(ss_speed, ss_density, 0);
4283 game_pal();
4284 }
4285 #else
4286 // The reason these are different on Mac in the first place is that
4287 // the OS doesn't let us use F9 and F10...
4288 if(zc_readkey(KEY_F10)) Showpal=!Showpal;
4289
4290 if(zc_readkey(KEY_F9))
4291 {
4292 Matrix(ss_speed, ss_density, 0);
4293 game_pal();
4294 }
4295 #endif
4296 if(zc_readkey(KEY_PLUS_PAD) || zc_readkey(KEY_EQUALS))
4297 {
4298 //change containers
4299 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4300 {
4301 //magic containers
4302 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4303 {
4304 game->set_maxmagic(zc_min(game->get_maxmagic()+game->get_mp_per_block(),game->get_mp_per_block()*8));
4305 }
4306 else
4307 {
4308 game->set_maxlife(zc_min(game->get_maxlife()+game->get_hp_per_heart(),game->get_hp_per_heart()*24));
4309 }
4310 }
4311 else
4312 {
4313 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4314 {
4315 game->set_magic(zc_min(game->get_magic()+1,game->get_maxmagic()));
4316 }
4317 else
4318 {
4319 game->set_life(zc_min(game->get_life()+1,game->get_maxlife()));
4320 }
4321 }
4322 }
4323
4324 if(zc_readkey(KEY_MINUS_PAD) || zc_readkey(KEY_MINUS))
4325 {
4326 //change containers
4327 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4328 {
4329 //magic containers
4330 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4331 {
4332 game->set_maxmagic(zc_max(game->get_maxmagic()-game->get_mp_per_block(),0));
4333 game->set_magic(zc_min(game->get_maxmagic(), game->get_magic()));
4334 //heart containers
4335 }
4336 else
4337 {
4338 game->set_maxlife(zc_max(game->get_maxlife()-game->get_hp_per_heart(),game->get_hp_per_heart()));
4339 game->set_life(zc_min(game->get_maxlife(), game->get_life()));
4340 }
4341 }
4342 else
4343 {
4344 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4345 {
4346 game->set_magic(zc_max(game->get_magic()-1,0));
4347 }
4348 else
4349 {
4350 game->set_life(zc_max(game->get_life()-1,0));
4351 }
4352 }
4353 }
4354
4355 if(zc_readkey(KEY_COMMA)) jukebox(currmidi-1);
4356
4357 if(zc_readkey(KEY_STOP)) jukebox(currmidi+1);
4358
4359 verifyBothWeapons();
4360
4361 bottom:
4362
4363
1/2
✓ Branch 0 taken 18519801 times.
✗ Branch 1 not taken.
18519801 if(input_idle(true) > after_time())
4364 {
4365 Matrix(ss_speed, ss_density, 0);
4366 game_pal();
4367 }
4368 18519801 }
4369
4370 9434950 void checkQuitKeys()
4371 {
4372 #ifndef ALLEGRO_MACOSX
4373
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9434950 times.
9434950 if(key[KEY_F9]) f_Quit(qRESET);
4374
4375
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9434950 times.
9434950 if(key[KEY_F10]) f_Quit(qEXIT);
4376 #else
4377 if(key[KEY_F7]) f_Quit(qRESET);
4378
4379 if(key[KEY_F8]) f_Quit(qEXIT);
4380 #endif
4381 9434950 }
4382
4383 18520001 bool CheatModifierKeys()
4384 {
4385 // Cheats are replayed via the X cheat step, no need to check for keyboard input
4386 // to trigger cheats.
4387
2/2
✓ Branch 0 taken 18519701 times.
✓ Branch 1 taken 300 times.
18520001 if (replay_is_replaying())
4388 18519701 return false;
4389
4390
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 200 times.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
300 if ( ( cheat_modifier_keys[0] > 0 && key[cheat_modifier_keys[0]] ) ||
4391
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 100 times.
200 ( cheat_modifier_keys[1] > 0 && key[cheat_modifier_keys[1]] ) ||
4392
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
100 (cheat_modifier_keys[0] <= 0 && cheat_modifier_keys[1] <= 0))
4393 {
4394
0/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
200 if ( ( cheat_modifier_keys[2] <= 0 || key[cheat_modifier_keys[2]] ) ||
4395 ( cheat_modifier_keys[3] > 0 && key[cheat_modifier_keys[3]] ) ||
4396 (cheat_modifier_keys[2] <= 0 && cheat_modifier_keys[3] <= 0))
4397 {
4398 return true;
4399 }
4400 }
4401 100 return false;
4402 18519801 }
4403
4404 //99:05:54, for some reason?
4405 #define OLDMAXTIME 21405240
4406 //9000:00:00, the highest even-thousand hour fitting within 32b signed. This is 375 *DAYS*.
4407 #define MAXTIME 1944000000
4408
4409 // (qr, value)
4410 414 static std::queue<std::pair<int, bool>> change_qr_queue;
4411
4412 7 void enqueue_qr_change(int qr, bool value)
4413 {
4414 7 change_qr_queue.push({qr, value});
4415 7 }
4416
4417 // During regular play, QR changes issued through `syskey` / `System` and enqueued
4418 // and soon executed here.
4419 // During playing back a replay file, the replay system adds to the same queue and
4420 // is executed here too.
4421 // This is currently only used to allow users to configure qr_HIDE_BOTTOM_8_PIXELS, but
4422 // could be later extended to all QRs (perhaps as a cheat).
4423 18520223 void process_enqueued_qr_changes()
4424 {
4425
2/2
✓ Branch 0 taken 101 times.
✓ Branch 1 taken 18520122 times.
18520223 if (replay_is_replaying())
4426 18520122 replay_do_qrs();
4427
4428
2/2
✓ Branch 0 taken 18520223 times.
✓ Branch 1 taken 7 times.
18520230 while (!change_qr_queue.empty())
4429 {
4430 28 auto [qr, value] = change_qr_queue.front();
4431 7 change_qr_queue.pop();
4432
4433 // Don't modify `quest_rules`, as that is used to store the canonical QR value which can be reset to
4434 // via system menus. Changing the unpacked array is enough to modify the engine's behavior.
4435 14 _qrs_unpacked[qr] = value;
4436 7 apply_qr_rule(qr);
4437
4438
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
7 if (replay_is_recording())
4439 2 replay_step_qr(qr, value);
4440 }
4441 18520223 }
4442
4443 18521188 void advanceframe(bool allowwavy, bool sfxcleanup, bool allowF6Script)
4444 {
4445
1/2
✓ Branch 0 taken 18521188 times.
✗ Branch 1 not taken.
18521188 if(zcmusic!=NULL)
4446 {
4447 zcmusic_poll();
4448 }
4449 18521188 zcmixer_update(zcmixer, emusic_volume, FFCore.usr_music_volume, get_qr(qr_OLD_SCRIPT_VOLUME));
4450
4451 18521188 updatescr(allowwavy);
4452
4453 18521188 Advance=false;
4454
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 18521188 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 18521188 times.
18521188 while(Paused && !Advance && !Quit)
4455 {
4456 // have to call this, otherwise we'll get an infinite loop
4457 syskeys();
4458 if(allowF6Script)
4459 {
4460 FFCore.runF6Engine();
4461 }
4462
4463 #ifdef _WIN32
4464
4465 if(use_dwm_flush)
4466 {
4467 do_DwmFlush();
4468 }
4469
4470 #endif
4471
4472 // to keep music playing
4473 if(zcmusic!=NULL)
4474 {
4475 zcmusic_poll();
4476 }
4477
4478 update_hw_screen();
4479 }
4480
4481
2/2
✓ Branch 0 taken 18519830 times.
✓ Branch 1 taken 1358 times.
18521188 if(Quit)
4482 1358 return;
4483
4484
3/4
✓ Branch 0 taken 18004460 times.
✓ Branch 1 taken 515370 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18004460 times.
18519830 if(Playing && game->get_time()<unsigned(get_qr(qr_GREATER_MAX_TIME) ? MAXTIME : OLDMAXTIME))
4485 18004460 game->change_time(1);
4486
4487 // Many mistakes have been make re: inputs, and we are stuck with many replays relying on those mistakes.
4488
4489 18519830 bool should_reset_down_state = !get_qr(qr_BROKEN_INPUT_DOWN_STATE);
4490
2/2
✓ Branch 0 taken 8720218 times.
✓ Branch 1 taken 9799612 times.
18519830 if (replay_version_check(0, 16))
4491 9799612 should_reset_down_state = replay_version_check(11, 16);
4492
2/2
✓ Branch 0 taken 15093802 times.
✓ Branch 1 taken 3426028 times.
18519830 if (should_reset_down_state)
4493 {
4494
2/2
✓ Branch 0 taken 61668504 times.
✓ Branch 1 taken 3426028 times.
65094532 for (int i = 0; i < ZC_CONTROL_STATES; i++)
4495 61668504 down_control_states[i] = raw_control_state[i];
4496 3426028 }
4497
4498
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 18519801 times.
18519830 if (replay_is_active())
4499 {
4500
2/2
✓ Branch 0 taken 1545428 times.
✓ Branch 1 taken 16974373 times.
18519801 if (replay_version_check(3))
4501 16974373 replay_poll();
4502
4503
4/4
✓ Branch 0 taken 7478911 times.
✓ Branch 1 taken 11040890 times.
✓ Branch 2 taken 100535 times.
✓ Branch 3 taken 7378376 times.
18519801 if (replay_version_check(11) || replay_version_check(6, 8))
4504 11141425 replay_peek_input();
4505 18519801 }
4506
4507 18519830 process_enqueued_qr_changes();
4508
4509 18519830 load_control_called_this_frame = false;
4510
4511 18519830 poll_keyboard();
4512 18519830 update_keys();
4513
4514 18519830 ++frame;
4515
4516
2/2
✓ Branch 0 taken 129 times.
✓ Branch 1 taken 18519701 times.
18519830 if (replay_is_replaying())
4517 18519701 replay_do_cheats();
4518 18519830 syskeys();
4519
4520 // The mouse variables can change from the mouse thread at anytime during a frame,
4521 // so save the result at the start so that replaying is consistent.
4522 18519830 script_mouse_x = gui_mouse_x();
4523 18519830 script_mouse_y = gui_mouse_y();
4524 18519830 script_mouse_z = mouse_z;
4525 18519830 script_mouse_b = mouse_b;
4526
4527 // Cheats used via the System menu (called by syskeys) will call cheats_enqueue. syskeys
4528 // is called just above, and in the paused loop above, so the queue-and-defer-slightly
4529 // approach here means it doesn't matter which call adds the cheat.
4530 18519830 cheats_execute_queued();
4531
4532
2/2
✓ Branch 0 taken 129 times.
✓ Branch 1 taken 18519701 times.
18519830 if (replay_is_replaying())
4533 18519701 replay_peek_quit();
4534
2/2
✓ Branch 0 taken 18519784 times.
✓ Branch 1 taken 46 times.
18519830 if (GameFlags & GAMEFLAG_TRYQUIT)
4535 46 replay_step_quit(0);
4536
2/2
✓ Branch 0 taken 3314 times.
✓ Branch 1 taken 18516516 times.
18519830 if(allowF6Script)
4537 18516516 FFCore.runF6Engine();
4538
2/2
✓ Branch 0 taken 755 times.
✓ Branch 1 taken 18519075 times.
18519830 if (Quit)
4539 755 replay_step_quit(Quit);
4540
4541 #ifdef _WIN32
4542
4543 if(use_dwm_flush)
4544 {
4545 do_DwmFlush();
4546 }
4547
4548 #endif
4549
4550
2/2
✓ Branch 0 taken 208637 times.
✓ Branch 1 taken 18311193 times.
18519830 if(sfxcleanup)
4551 18311193 sfx_cleanup();
4552
4553 18519830 jit_poll();
4554
4555 18519830 frame_timings_poll();
4556
4557 #ifdef __EMSCRIPTEN__
4558 // Yield the main thread back to the browser occasionally.
4559 if (is_headless())
4560 {
4561 static int rate = 10000;
4562 static int force_yield = rate;
4563 if (force_yield++ >= rate)
4564 {
4565 force_yield = 0;
4566 emscripten_sleep(0);
4567 }
4568 }
4569 #endif
4570
4571
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 18519730 times.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
18519830 if (zqtesting_mode && test_mode_auto_restart)
4572 {
4573 static auto last_write_time = fs::last_write_time(qstpath);
4574 static auto last_check = std::chrono::system_clock::now();
4575
4576 if (std::chrono::system_clock::now() - last_check > 200ms)
4577 {
4578 last_check = std::chrono::system_clock::now();
4579 auto write_time = fs::last_write_time(qstpath);
4580 if (last_write_time != write_time)
4581 {
4582 last_write_time = write_time;
4583 disableClickToFreeze = false;
4584 Quit = qRESET;
4585 replay_quit();
4586 }
4587 }
4588 }
4589 18521188 }
4590
4591 590 void zapout()
4592 {
4593 590 set_clip_rect(scrollbuf_old, 0, 0, scrollbuf_old->w, scrollbuf_old->h);
4594 590 blit(framebuf,scrollbuf_old,0,0,256,0,256,framebuf->h);
4595
4596 590 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4597 590 script_drawing_commands.Clear();
4598
4599 // zap out
4600
2/2
✓ Branch 0 taken 590 times.
✓ Branch 1 taken 14160 times.
14750 for(int32_t i=1; i<=24; i++)
4601 {
4602 14160 draw_fuzzy(i);
4603 14160 advanceframe(true);
4604
4605
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14160 times.
14160 if(Quit)
4606 {
4607 break;
4608 }
4609 14160 }
4610 590 }
4611
4612 588 void zapin()
4613 {
4614 588 FFCore.warpScriptCheck();
4615 588 draw_screen();
4616 588 set_clip_rect(scrollbuf_old, 0, 0, scrollbuf_old->w, scrollbuf_old->h);
4617 588 blit(framebuf,scrollbuf_old,0,0,256,0,256,framebuf->h);
4618
4619 // zap out
4620 588 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4621
2/2
✓ Branch 0 taken 588 times.
✓ Branch 1 taken 14112 times.
14700 for(int32_t i=24; i>=1; i--)
4622 {
4623 14112 draw_fuzzy(i);
4624 14112 advanceframe(true);
4625
4626
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14112 times.
14112 if(Quit)
4627 {
4628 break;
4629 }
4630 14112 }
4631 588 }
4632
4633
4634 235 void wavyout(bool showhero)
4635 {
4636 235 draw_screen(showhero);
4637
4638 235 BITMAP *wavebuf = create_bitmap_ex(8,288,framebuf->h);
4639 235 clear_to_color(wavebuf,0);
4640 235 blit(framebuf,wavebuf,0,0,16,0,framebuf->w,framebuf->h);
4641
4642 static PALETTE wavepal;
4643
4644 int32_t ofs;
4645 235 int32_t amplitude=8;
4646
4647 235 int32_t wavelength=4;
4648 235 int height = viewport.visible_height(show_bottom_8px);
4649 235 double palpos=0, palstep=4, palstop=126;
4650
4651 235 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4652
2/2
✓ Branch 0 taken 234 times.
✓ Branch 1 taken 9845 times.
10079 for(int32_t i=0; i<height; i+=wavelength)
4653 {
4654
2/2
✓ Branch 0 taken 2520320 times.
✓ Branch 1 taken 9845 times.
2530165 for(int32_t l=0; l<256; l++)
4655 {
4656 2520320 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(255-RAMpal[l].r))),0,255);
4657 2520320 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(255-RAMpal[l].g))),0,255);
4658 2520320 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(255-RAMpal[l].b))),0,255);
4659 2520320 }
4660
4661 9845 palpos+=palstep;
4662
4663
1/2
✓ Branch 0 taken 9845 times.
✗ Branch 1 not taken.
9845 if(palpos>=0)
4664 {
4665 9845 hw_palette = &wavepal;
4666 9845 update_hw_pal = true;
4667 9845 }
4668 else
4669 {
4670 hw_palette = &RAMpal;
4671 update_hw_pal = true;
4672 }
4673
4674
2/2
✓ Branch 0 taken 1653960 times.
✓ Branch 1 taken 9845 times.
1663805 for(int32_t j=0; j+playing_field_offset<framebuf->h; j++)
4675 {
4676
2/2
✓ Branch 0 taken 423413760 times.
✓ Branch 1 taken 1653960 times.
425067720 for(int32_t k=0; k<256; k++)
4677 {
4678 423413760 ofs=0;
4679
4680
4/4
✓ Branch 0 taken 206448640 times.
✓ Branch 1 taken 216965120 times.
✓ Branch 2 taken 103224320 times.
✓ Branch 3 taken 103224320 times.
423413760 if((j<i)&&(j&1))
4681 {
4682 103224320 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/height))*amplitude);
4683 103224320 }
4684
4685 423413760 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4686 423413760 }
4687 1653960 }
4688
4689 9845 advanceframe(true);
4690
4691
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9844 times.
9845 if(Quit)
4692 1 break;
4693 9844 }
4694
4695 235 destroy_bitmap(wavebuf);
4696
4697 235 hw_palette = &RAMpal;
4698 235 update_hw_pal = true;
4699 235 }
4700
4701 232 void wavyin()
4702 {
4703 232 draw_screen();
4704
4705 232 BITMAP *wavebuf = create_bitmap_ex(8,288,framebuf->h);
4706 232 clear_to_color(wavebuf,0);
4707 232 blit(framebuf,wavebuf,0,0,16,0,framebuf->w,framebuf->h);
4708
4709 static PALETTE wavepal;
4710
4711 232 refreshpal=false;
4712 int32_t ofs;
4713 232 int32_t amplitude=8;
4714 232 int32_t wavelength=4;
4715 232 int height = viewport.visible_height(show_bottom_8px);
4716 232 double palpos=height, palstep=4, palstop=126;
4717
4718 232 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4719
2/2
✓ Branch 0 taken 231 times.
✓ Branch 1 taken 9703 times.
9934 for(int32_t i=0; i<height; i+=wavelength)
4720 {
4721
2/2
✓ Branch 0 taken 2483968 times.
✓ Branch 1 taken 9703 times.
2493671 for(int32_t l=0; l<256; l++)
4722 {
4723 2483968 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(255-RAMpal[l].r))),0,255);
4724 2483968 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(255-RAMpal[l].g))),0,255);
4725 2483968 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(255-RAMpal[l].b))),0,255);
4726 2483968 }
4727
4728 9703 palpos-=palstep;
4729
4730
1/2
✓ Branch 0 taken 9703 times.
✗ Branch 1 not taken.
9703 if(palpos>=0)
4731 {
4732 9703 hw_palette = &wavepal;
4733 9703 update_hw_pal = true;
4734 9703 }
4735 else
4736 {
4737 hw_palette = &RAMpal;
4738 update_hw_pal = true;
4739 }
4740
4741
2/2
✓ Branch 0 taken 1630104 times.
✓ Branch 1 taken 9703 times.
1639807 for(int32_t j=0; j+playing_field_offset<framebuf->h; j++)
4742 {
4743
2/2
✓ Branch 0 taken 417306624 times.
✓ Branch 1 taken 1630104 times.
418936728 for(int32_t k=0; k<256; k++)
4744 {
4745 417306624 ofs=0;
4746
4747
4/4
✓ Branch 0 taken 211158272 times.
✓ Branch 1 taken 206148352 times.
✓ Branch 2 taken 106821120 times.
✓ Branch 3 taken 104337152 times.
417306624 if((j<(height-1-i))&&(j&1))
4748 {
4749 104337152 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/height))*amplitude);
4750 104337152 }
4751
4752 417306624 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4753 417306624 }
4754 1630104 }
4755
4756 9703 advanceframe(true);
4757
4758
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9702 times.
9703 if(Quit)
4759 1 break;
4760 9702 }
4761
4762 232 destroy_bitmap(wavebuf);
4763
4764 232 hw_palette = &RAMpal;
4765 232 update_hw_pal = true;
4766 232 }
4767
4768 4346 void blackscr(int32_t fcnt,bool showsubscr)
4769 {
4770 4346 reset_pal_cycling();
4771 4346 script_drawing_commands.Clear();
4772
4773 4346 FFCore.warpScriptCheck();
4774 4346 bool showtime = game->should_show_time();
4775
2/2
✓ Branch 0 taken 4339 times.
✓ Branch 1 taken 129937 times.
134276 while(fcnt>0)
4776 {
4777 129937 clear_bitmap(framebuf);
4778
4779
2/2
✓ Branch 0 taken 59310 times.
✓ Branch 1 taken 70627 times.
129937 if(showsubscr)
4780 {
4781 70627 put_passive_subscr(framebuf,0,0,showtime,sspUP);
4782
3/4
✓ Branch 0 taken 70627 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1410 times.
✓ Branch 3 taken 69217 times.
70627 if(get_qr(qr_SCRIPTDRAWSINWARPS) || (get_qr(qr_PASSIVE_SUBSCRIPT_RUNS_WHEN_GAME_IS_FROZEN)))
4783 {
4784 1410 do_script_draws(framebuf, origin_scr, 0, playing_field_offset);
4785 1410 }
4786 70627 }
4787
4788 129937 advanceframe(true);
4789
4790
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 129930 times.
129937 if(Quit)
4791 7 break;
4792
4793 129930 --fcnt;
4794 }
4795 4346 }
4796
4797 2738 void openscreen(int32_t shape)
4798 {
4799 2738 update_viewport();
4800 2738 is_opening_screen = true;
4801 2738 reset_pal_cycling();
4802 2738 black_opening_count=0;
4803
4804
3/4
✓ Branch 0 taken 531 times.
✓ Branch 1 taken 2207 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 531 times.
2738 if(COOLSCROLL || shape>-1)
4805 {
4806 2207 open_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4807 2207 return;
4808 }
4809 else
4810 {
4811 531 Hero.setDontDraw(true);
4812 531 show_subscreen_dmap_dots=false;
4813 531 show_subscreen_numbers=false;
4814 531 show_subscreen_life=false;
4815 }
4816
4817 531 int32_t x=128;
4818
4819 531 FFCore.warpScriptCheck();
4820
2/2
✓ Branch 0 taken 531 times.
✓ Branch 1 taken 42480 times.
43011 for(int32_t i=0; i<80; i++)
4821 {
4822 42480 draw_screen();
4823 42480 x=128-(((i*128/80)/8)*8);
4824
4825
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42480 times.
42480 if(x>0)
4826 {
4827 42480 rectfill(framebuf,0,playing_field_offset,x,(viewport.h - 1)+playing_field_offset,0);
4828 42480 rectfill(framebuf,viewport.w-x,playing_field_offset,255,(viewport.h - 1)+playing_field_offset,0);
4829 42480 }
4830
4831 42480 advanceframe(true);
4832
4833
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42480 times.
42480 if(Quit)
4834 {
4835 break;
4836 }
4837 42480 }
4838
4839 531 Hero.setDontDraw(false);
4840 531 show_subscreen_items=true;
4841 531 show_subscreen_dmap_dots=true;
4842 531 show_subscreen_numbers=true;
4843 531 show_subscreen_life=true;
4844 2738 }
4845
4846 14 void closescreen(int32_t shape)
4847 {
4848 14 is_opening_screen = false;
4849 14 reset_pal_cycling();
4850 14 black_opening_count=0;
4851
4852
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
14 if(COOLSCROLL || shape>-1)
4853 {
4854 14 close_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4855 14 return;
4856 }
4857 else
4858 {
4859 Hero.setDontDraw(true);
4860 show_subscreen_dmap_dots=false;
4861 show_subscreen_numbers=false;
4862 // show_subscreen_items=false;
4863 show_subscreen_life=false;
4864 }
4865
4866 int32_t x=128;
4867
4868 FFCore.warpScriptCheck();
4869 for(int32_t i=79; i>=0; --i)
4870 {
4871 draw_screen();
4872 x=128-(((i*128/80)/8)*8);
4873
4874 if(x>0)
4875 {
4876 rectfill(framebuf,0,playing_field_offset,x,(viewport.h - 1)+playing_field_offset,0);
4877 rectfill(framebuf,viewport.w-x,playing_field_offset,255,(viewport.h - 1)+playing_field_offset,0);
4878 }
4879
4880 advanceframe(true);
4881
4882 if(Quit)
4883 {
4884 break;
4885 }
4886 }
4887
4888 Hero.setDontDraw(false);
4889 show_subscreen_items=true;
4890 show_subscreen_dmap_dots=true;
4891 14 }
4892
4893 324 int32_t TriforceCount()
4894 {
4895 324 int32_t c=0;
4896
4897
2/2
✓ Branch 0 taken 2592 times.
✓ Branch 1 taken 324 times.
2916 for(int32_t i=1; i<=8; i++)
4898
2/2
✓ Branch 0 taken 484 times.
✓ Branch 1 taken 2108 times.
4700 if(game->lvlitems[i]&liTRIFORCE)
4899 2108 ++c;
4900
4901 324 return c;
4902 }
4903
4904 int32_t onCustomGame()
4905 {
4906 auto save = get_unset_save_slot();
4907 if (!save)
4908 return D_CLOSE;
4909
4910 if (prompt_for_quest_path(save->header->qstpath))
4911 {
4912 save->header->qstpath = qstpath;
4913 return D_O_K;
4914 }
4915
4916 return D_CLOSE;
4917 }
4918
4919 int32_t onContinue()
4920 {
4921 return D_CLOSE;
4922 }
4923
4924 int32_t onThrottleFPS()
4925 {
4926 Throttlefps = !Throttlefps;
4927 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4928 return D_O_K;
4929 }
4930
4931 int32_t onWinPosSave()
4932 {
4933 SaveWinPos = !SaveWinPos;
4934 zc_set_config(cfg_sect,"save_window_position",(int32_t)SaveWinPos);
4935 return D_O_K;
4936 }
4937 int32_t onIntegerScaling()
4938 {
4939 scaleForceInteger = !scaleForceInteger;
4940 zc_set_config("zeldadx","scaling_force_integer",(int)scaleForceInteger);
4941 return D_O_K;
4942 }
4943 int32_t onStretchGame()
4944 {
4945 stretchGame = !stretchGame;
4946 zc_set_config("zeldadx","stretch_game_area",stretchGame?1:0);
4947 return D_O_K;
4948 }
4949
4950 int32_t onClickToFreeze()
4951 {
4952 ClickToFreeze = !ClickToFreeze;
4953 zc_set_config(cfg_sect,"clicktofreeze", (int32_t)ClickToFreeze);
4954 return D_O_K;
4955 }
4956
4957 int32_t OnSaveZCConfig()
4958 {
4959 if(jwin_alert3(
4960 "Save Configuration",
4961 "Are you sure that you wish to save your present configuration settings?",
4962 "This will overwrite your prior settings!",
4963 NULL,
4964 "&Yes",
4965 "&No",
4966 NULL,
4967 'y',
4968 'n',
4969 0,
4970 get_zc_font(font_lfont)) == 1)
4971 {
4972 save_game_configs();
4973 return D_O_K;
4974 }
4975 else return D_O_K;
4976 }
4977
4978 int32_t OnnClearQuestDir()
4979 {
4980 auto current_path = fs::current_path() / "quests";
4981 if(jwin_alert3(
4982 "Clear Current Directory Cache",
4983 "Are you sure that you wish to reset where ZC Player looks for quests?",
4984 fmt::format("The new directory will be: {}", current_path.string()).c_str(),
4985 NULL,
4986 "&Yes",
4987 "&No",
4988 NULL,
4989 'y',
4990 'n',
4991 0,
4992 get_zc_font(font_lfont)) == 1)
4993 {
4994 zc_set_config("zeldadx","quest_dir","quests");
4995 flush_config_file();
4996 strcpy(qstdir,"quests");
4997 #ifdef __EMSCRIPTEN__
4998 em_sync_fs();
4999 #endif
5000 return D_O_K;
5001 }
5002 else return D_O_K;
5003 }
5004
5005 int32_t onConsole()
5006 {
5007 if ( !console_enabled )
5008 {
5009 AlertDialog("ZC Console",
5010 "Open the ZC Console?"
5011 "\nThis will display any messages logged by scripts,"
5012 " including errors.",
5013 [&](bool ret,bool)
5014 {
5015 if(ret)
5016 {
5017 FFCore.ZScriptConsole(true);
5018 }
5019 }).show();
5020 return D_O_K;
5021 }
5022 else
5023 {
5024 FFCore.ZScriptConsole(false);
5025 return D_O_K;
5026 }
5027 }
5028
5029 int32_t onClrConsoleOnReload()
5030 {
5031 clearConsoleOnReload = !clearConsoleOnReload;
5032 zc_set_config("CONSOLE","clear_console_on_reload",clearConsoleOnReload?1:0);
5033 return D_O_K;
5034 }
5035 int32_t onClrConsoleOnLoad()
5036 {
5037 clearConsoleOnLoad = !clearConsoleOnLoad;
5038 zc_set_config("CONSOLE","clear_console_on_load",clearConsoleOnLoad?1:0);
5039 return D_O_K;
5040 }
5041
5042
5043 int32_t onFrameSkip()
5044 {
5045 FrameSkip = !FrameSkip;
5046 return D_O_K;
5047 }
5048
5049 int32_t onSaveDragResize()
5050 {
5051 SaveDragResize = !SaveDragResize;
5052 zc_set_config(cfg_sect,"save_drag_resize",(int32_t)SaveDragResize);
5053 return D_O_K;
5054 }
5055
5056 int32_t onDragAspect()
5057 {
5058 DragAspect = !DragAspect;
5059 zc_set_config(cfg_sect,"drag_aspect",(int32_t)DragAspect);
5060 return D_O_K;
5061 }
5062
5063 int32_t onTransLayers()
5064 {
5065 TransLayers = !TransLayers;
5066 zc_set_config(cfg_sect,"translayers",(int32_t)TransLayers);
5067 return D_O_K;
5068 }
5069
5070 int32_t onNESquit()
5071 {
5072 NESquit = !NESquit;
5073 zc_set_config(cfg_sect,"fastquit",(int32_t)NESquit);
5074 return D_O_K;
5075 }
5076
5077 int32_t onVolKeys()
5078 {
5079 volkeys = !volkeys;
5080 zc_set_config(sfx_sect,"volkeys",(int32_t)volkeys);
5081 return D_O_K;
5082 }
5083
5084 int32_t onShowFPS()
5085 {
5086 ShowFPS = !ShowFPS;
5087 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
5088 return D_O_K;
5089 }
5090
5091 int32_t onShowTime()
5092 {
5093 ShowGameTime = !ShowGameTime;
5094 zc_set_config(cfg_sect,"showtime",ShowGameTime);
5095 return D_O_K;
5096 }
5097
5098 2185336518 bool is_Fkey(int32_t k)
5099 {
5100
2/2
✓ Branch 0 taken 222237612 times.
✓ Branch 1 taken 1963098906 times.
2185336518 switch(k)
5101 {
5102 case KEY_F1:
5103 case KEY_F2:
5104 case KEY_F3:
5105 case KEY_F4:
5106 case KEY_F5:
5107 case KEY_F6:
5108 case KEY_F7:
5109 case KEY_F8:
5110 case KEY_F9:
5111 case KEY_F10:
5112 case KEY_F11:
5113 case KEY_F12:
5114 222237612 return true;
5115 }
5116
5117 1963098906 return false;
5118 2185336518 }
5119
5120 void kb_getkey(DIALOG *d);
5121
5122 //Used by all keyboard key settings dialogues.
5123 void kb_clearjoystick(DIALOG *d)
5124 {
5125 d->flags|=D_SELECTED;
5126
5127 jwin_button_proc(MSG_DRAW,d,0);
5128 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5129 // text_mode(vc(11));
5130 textout_centre_ex(screen, font, "Press any key to clear", gui_bmp->w/2, gui_bmp->h/2 - 8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5131 textout_centre_ex(screen, font, "ESC to cancel", gui_bmp->w/2, gui_bmp->h/2, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5132
5133 update_hw_screen();
5134
5135 clear_keybuf();
5136 int32_t k = next_press_key();
5137 clear_keybuf();
5138
5139 //shnarf
5140 //47=f1
5141 //59=esc
5142 // if(k>0 && k<123 && !((k>46)&&(k<60)))
5143 // *((int32_t*)d->dp3) = k;
5144 if ( k != 59 ) *((int32_t*)d->dp3) = 0;
5145
5146
5147 d->flags&=~D_SELECTED;
5148 }
5149
5150 //Clears key to 0.
5151 //Used by all keyboard key settings dialogues.
5152 void kb_clearkey(DIALOG *d);
5153
5154 int32_t d_j_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5155 {
5156 switch(msg)
5157 {
5158 case MSG_KEY:
5159 case MSG_CLICK:
5160
5161 kb_clearjoystick(d);
5162
5163 while(gui_mouse_b())
5164 {
5165 clear_keybuf();
5166 rest(1);
5167 }
5168
5169 return D_REDRAW;
5170 }
5171
5172 return jwin_button_proc(msg,d,c);
5173 }
5174
5175 int32_t d_kbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5176 //Only used in keyboard settings dialogues to clear keys.
5177 int32_t d_k_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5178
5179 int32_t j_getbtn(DIALOG *d)
5180 {
5181 d->flags|=D_SELECTED;
5182 jwin_button_proc(MSG_DRAW,d,0);
5183 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5184 // text_mode(vc(11));
5185 int32_t y = screen->h/2 - 12;
5186 textout_centre_ex(screen, font, "Press a button", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5187 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5188 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5189
5190 update_hw_screen();
5191
5192 int32_t b = next_joy_input(true);
5193 if (b == -2)
5194 return D_CLOSE;
5195
5196 if(b>=0)
5197 *((int32_t*)d->dp3) = b;
5198
5199 d->flags&=~D_SELECTED;
5200
5201 return D_O_K;
5202 }
5203
5204 void j_getstick(DIALOG *d)
5205 {
5206 d->flags|=D_SELECTED;
5207 jwin_button_proc(MSG_DRAW,d,0);
5208 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5209 // text_mode(vc(11));
5210 int32_t y = screen->h/2 - 12;
5211 textout_centre_ex(screen, font, "Move a stick (or DPAD)", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5212 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5213 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5214
5215 update_hw_screen();
5216
5217 int32_t b = next_joy_input(false);
5218
5219 if(b>=0)
5220 *((int32_t*)d->dp3) = b;
5221
5222 d->flags&=~D_SELECTED;
5223 }
5224
5225 int32_t d_jbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5226 {
5227 switch(msg)
5228 {
5229 case MSG_KEY:
5230 case MSG_CLICK:
5231
5232 int ret = j_getbtn(d);
5233 if (ret != D_O_K)
5234 return ret;
5235
5236 while(gui_mouse_b()) {
5237 rest(1);
5238 clear_keybuf();
5239 }
5240
5241 return D_REDRAW;
5242 }
5243
5244 return jwin_button_proc(msg,d,c);
5245 }
5246
5247 int32_t d_jstick_proc(int32_t msg,DIALOG *d,int32_t c)
5248 {
5249 switch(msg)
5250 {
5251 case MSG_KEY:
5252 case MSG_CLICK:
5253
5254 j_getstick(d);
5255
5256 while(gui_mouse_b()) {
5257 rest(1);
5258 clear_keybuf();
5259 }
5260
5261 return D_REDRAW;
5262 }
5263
5264 return jwin_button_proc(msg,d,c);
5265 }
5266
5267 //shnarf
5268 extern const char *key_str[];
5269 std::string get_keystr(int key);
5270
5271 const char *pan_str[4] = { " MONO", " 1/2", " 3/4", " FULL" };
5272
5273 static char str_a[80],str_b[80],str_s[80],str_m[80],str_l[80],str_r[80],str_p[80],str_ex1[80],str_ex2[80],str_ex3[80],str_ex4[80],
5274 str_leftmod1[80],str_leftmod2[80],str_rightmod1[80],str_rightmod2[80], str_left[80], str_right[80], str_up[80], str_down[80],
5275 str_primary_stick[80], str_secondary_stick[80];
5276
5277 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c)
5278 {
5279 //these are here to bypass compiler warnings about unused arguments
5280 c=c;
5281
5282 if (d->w == 1)
5283 {
5284 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
5285 {
5286 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
5287 return D_CLOSE;
5288 }
5289 }
5290
5291 if(msg==MSG_DRAW)
5292 {
5293 switch(d->w)
5294 {
5295 case 0:
5296 sprintf(str_a,"%03d\n%s",Akey,key_str[Akey]);
5297 sprintf(str_b,"%03d\n%s",Bkey,key_str[Bkey]);
5298 sprintf(str_s,"%03d\n%s",Skey,key_str[Skey]);
5299 sprintf(str_l,"%03d\n%s",Lkey,key_str[Lkey]);
5300 sprintf(str_r,"%03d\n%s",Rkey,key_str[Rkey]);
5301 sprintf(str_p,"%03d\n%s",Pkey,key_str[Pkey]);
5302 sprintf(str_ex1,"%03d\n%s",Exkey1,key_str[Exkey1]);
5303 sprintf(str_ex2,"%03d\n%s",Exkey2,key_str[Exkey2]);
5304 sprintf(str_ex3,"%03d\n%s",Exkey3,key_str[Exkey3]);
5305 sprintf(str_ex4,"%03d\n%s",Exkey4,key_str[Exkey4]);
5306 sprintf(str_up,"%03d\n%s",DUkey,key_str[DUkey]);
5307 sprintf(str_down,"%03d\n%s",DDkey,key_str[DDkey]);
5308 sprintf(str_left,"%03d\n%s",DLkey,key_str[DLkey]);
5309 sprintf(str_right,"%03d\n%s",DRkey,key_str[DRkey]);
5310 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5311 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5312 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5313 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5314 break;
5315
5316 case 1:
5317 sprintf(str_a,"%03d\n%s",Abtn,joybtn_name(Abtn));
5318 sprintf(str_b,"%03d\n%s",Bbtn,joybtn_name(Bbtn));
5319 sprintf(str_s,"%03d\n%s",Sbtn,joybtn_name(Sbtn));
5320 sprintf(str_l,"%03d\n%s",Lbtn,joybtn_name(Lbtn));
5321 sprintf(str_r,"%03d\n%s",Rbtn,joybtn_name(Rbtn));
5322 sprintf(str_m,"%03d\n%s",Mbtn,joybtn_name(Mbtn));
5323 sprintf(str_p,"%03d\n%s",Pbtn,joybtn_name(Pbtn));
5324 sprintf(str_ex1,"%03d\n%s",Exbtn1,joybtn_name(Exbtn1));
5325 sprintf(str_ex2,"%03d\n%s",Exbtn2,joybtn_name(Exbtn2));
5326 sprintf(str_ex3,"%03d\n%s",Exbtn3,joybtn_name(Exbtn3));
5327 sprintf(str_ex4,"%03d\n%s",Exbtn4,joybtn_name(Exbtn4));
5328 sprintf(str_up,"%03d\n%s",DUbtn,joybtn_name(DUbtn));
5329 sprintf(str_down,"%03d\n%s",DDbtn,joybtn_name(DDbtn));
5330 sprintf(str_left,"%03d\n%s",DLbtn,joybtn_name(DLbtn));
5331 sprintf(str_right,"%03d\n%s",DRbtn,joybtn_name(DRbtn));
5332 sprintf(str_primary_stick,"%03d\n%s",js_stick_1_x_stick,joystick_name(js_stick_1_x_stick));
5333 sprintf(str_secondary_stick,"%03d\n%s",js_stick_2_x_stick,joystick_name(js_stick_2_x_stick));
5334 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5335 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5336 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5337 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5338 break;
5339
5340 case 2:
5341 sprintf(str_a," %3d",midi_volume);
5342 sprintf(str_l," %3d",emusic_volume);
5343 sprintf(str_r," %3d",sfx_volume);
5344 strcpy(str_s,pan_str[pan_style]);
5345 sprintf(str_leftmod1,"%3d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5346 sprintf(str_leftmod2,"%3d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5347 sprintf(str_rightmod1,"%3d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5348 sprintf(str_rightmod2,"%3d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5349 break;
5350 }
5351 }
5352
5353 return D_O_K;
5354 }
5355
5356 int32_t set_vol(void *dp3, int32_t d2)
5357 {
5358 switch(((int32_t*)dp3)[0])
5359 {
5360 case 0:
5361 midi_volume = zc_min(d2<<3,255);
5362 break;
5363
5364 case 1:
5365 digi_volume = zc_min(d2<<3,255);
5366 break;
5367
5368 case 2:
5369 emusic_volume = zc_min(d2<<3,255);
5370 break;
5371
5372 case 3:
5373 sfx_volume = zc_min(d2<<3,255);
5374 break;
5375 }
5376
5377 // text_mode(vc(11));
5378 textprintf_right_ex(screen,get_zc_font(font_lfont_l), ((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]," %3d",zc_min(d2<<3,255));
5379 return D_O_K;
5380 }
5381
5382 int32_t set_pan(void *dp3, int32_t d2)
5383 {
5384 pan_style = vbound(d2,0,3);
5385 // text_mode(vc(11));
5386 textout_right_ex(screen,get_zc_font(font_lfont_l), pan_str[pan_style],((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5387 return D_O_K;
5388 }
5389
5390 static int32_t gamepad_joys_list[] =
5391 {
5392 61,
5393 -1
5394 };
5395
5396 static int32_t gamepad_btn_list[] =
5397 {
5398 6,
5399 7,8,9,10,11,12,13,14,15,16,17,
5400 18,19,20,21,22,23,24,25,26,27,28,
5401 29,30,31,32,33,34,35,36,37,38,39,
5402 -1
5403 };
5404
5405 static int32_t gamepad_dirs_list[] =
5406 {
5407 40,41,42,43,
5408 44,45,46,47,
5409 48,49,50,51,
5410 52,53,54,55,
5411 56,57,58,59,
5412 60,
5413 -1
5414 };
5415
5416 static TABPANEL gamepad_tabs[] =
5417 {
5418 // (text)
5419 { (char *)"Controllers", D_SELECTED, gamepad_joys_list, 0, NULL },
5420 { (char *)"Buttons", 0, gamepad_btn_list, 0, NULL },
5421 { (char *)"Directions", 0, gamepad_dirs_list, 0, NULL },
5422 { NULL, 0, NULL, 0, NULL }
5423 };
5424
5425 const char *joy_list(int32_t index, int32_t *list_size)
5426 {
5427 if (index == -1)
5428 {
5429 *list_size = al_get_num_joysticks();
5430 return NULL;
5431 }
5432
5433 ALLEGRO_JOYSTICK* joy = al_get_joystick(index);
5434 if (!joy)
5435 {
5436 return "?";
5437 }
5438
5439 return al_get_joystick_name(joy);
5440 }
5441
5442 414 static ListData joy__list(joy_list, &font);
5443
5444 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c)
5445 {
5446 int32_t d2 = d->d2;
5447 int32_t ret = jwin_droplist_proc(msg,d,c);
5448
5449 if(d2!=d->d2)
5450 {
5451 joystick_index = d->d2;
5452 ret |= D_REDRAW_ALL;
5453 }
5454
5455 return ret;
5456 }
5457
5458 static DIALOG gamepad_dlg[] =
5459 {
5460 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5461 { jwin_win_proc, 8, 24, 304, 256, 0, 0, 0, D_EXIT, 0, 0, (void *) "Gamepad Controls", NULL, NULL },
5462 { jwin_tab_proc, 8+4, 24+23,304-8,256-52,vc(0), vc(15), 0, 0, 0, 0, (void *) gamepad_tabs, NULL, (void *)gamepad_dlg },
5463 { d_stringloader, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5464 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5465 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5466 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5467 // 6
5468 { d_dummy_proc, 14, 61, 294, 192, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5469 // 7
5470 { jwin_ctext_proc, 92, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5471 { jwin_ctext_proc, 92, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5472 { jwin_ctext_proc, 92, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5473 { jwin_ctext_proc, 92, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5474 { jwin_ctext_proc, 92, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5475 { jwin_ctext_proc, 237, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5476 { jwin_ctext_proc, 237, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5477 { jwin_ctext_proc, 237, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5478 { jwin_ctext_proc, 237, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5479 { jwin_ctext_proc, 237, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5480 { jwin_ctext_proc, 92, 244-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_m, NULL, NULL },
5481 // 18
5482 { d_jbutton_proc, 22, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Abtn},
5483 { d_jbutton_proc, 22, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bbtn},
5484 { d_jbutton_proc, 22, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Sbtn},
5485 { d_jbutton_proc, 22, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exbtn1},
5486 { d_jbutton_proc, 22, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exbtn3},
5487 { d_jbutton_proc, 167, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lbtn},
5488 { d_jbutton_proc, 167, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rbtn},
5489 { d_jbutton_proc, 167, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pbtn},
5490 { d_jbutton_proc, 167, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exbtn2},
5491 { d_jbutton_proc, 167, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exbtn4},
5492 { d_jbutton_proc, 22, 242-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Menu", NULL, &Mbtn},
5493 // 29
5494 { d_j_clearbutton_proc, 22+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Abtn},
5495 { d_j_clearbutton_proc, 22+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bbtn},
5496 { d_j_clearbutton_proc, 22+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Sbtn},
5497 { d_j_clearbutton_proc, 22+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn1},
5498 { d_j_clearbutton_proc, 22+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn3},
5499 { d_j_clearbutton_proc, 167+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lbtn},
5500 { d_j_clearbutton_proc, 167+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rbtn},
5501 { d_j_clearbutton_proc, 167+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pbtn},
5502 { d_j_clearbutton_proc, 167+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn2},
5503 { d_j_clearbutton_proc, 167+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn4},
5504 { d_j_clearbutton_proc, 22+91, 242-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Mbtn},
5505 // 40
5506 { jwin_frame_proc, 14, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5507 { jwin_frame_proc, 159, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5508 { jwin_text_proc, 30, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5509 { jwin_text_proc, 175, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5510 // 44
5511 { jwin_text_proc, 92, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5512 { jwin_text_proc, 92, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5513 { jwin_text_proc, 237, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5514 { jwin_text_proc, 237, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5515 // 48
5516 { d_jbutton_proc, 22, 82, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUbtn },
5517 { d_jbutton_proc, 22, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDbtn },
5518 { d_jbutton_proc, 167, 82, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLbtn },
5519 { d_jbutton_proc, 167, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRbtn },
5520 // 52
5521 { d_j_clearbutton_proc, 22+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUbtn},
5522 { d_j_clearbutton_proc, 22+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDbtn},
5523 { d_j_clearbutton_proc, 167+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLbtn},
5524 { d_j_clearbutton_proc, 167+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRbtn},
5525 // 56
5526 { jwin_check_proc, 22, 150, 147, 8, vc(14), vc(1), 0, 0, 1, 0, (void *) "Primary: Use Analog Stick (Ignore above and use below instead)", NULL, NULL },
5527 { d_jstick_proc, 22, 165, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Primary", NULL, &js_stick_1_x_stick },
5528 { d_jstick_proc, 22, 195, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Secondary", NULL, &js_stick_2_x_stick },
5529 { jwin_text_proc, 90, 165, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_primary_stick, NULL, NULL },
5530 { jwin_text_proc, 90, 195, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_secondary_stick, NULL, NULL },
5531
5532 // 61
5533 { d_joylist_proc, 22, 62, 150, 16, 0, 0, 0, 0, 0, 0, (void *) &joy__list, NULL, NULL },
5534
5535 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5536 };
5537
5538 static int32_t keyboard_keys_list[] =
5539 {
5540 6,7,8,9,10,
5541 11,12,13,14,15,16,17,18,19,20,
5542 21,22,23,24,25,26,27,28,29,30,
5543 31,32,33,34,35,36,37,38,39,40,
5544 -1
5545 };
5546
5547 static int32_t keyboard_dirs_list[] =
5548 {
5549 41,42,43,44,
5550 45,46,47,48,
5551 49,50,51,52,
5552 53,54,55,56,
5553 -1
5554 };
5555
5556 static int32_t keyboard_mods_list[] =
5557 {
5558 57,58,59,60,
5559 61,62,63,64,
5560 65,66,67,68,
5561 69,70,71,72,
5562 -1
5563 };
5564
5565 static TABPANEL keyboard_control_tabs[] =
5566 {
5567 // (text)
5568 { (char *)"Keys", D_SELECTED, keyboard_keys_list, 0, NULL },
5569 { (char *)"Directions", 0, keyboard_dirs_list, 0, NULL },
5570 { (char *)"Cheat Mods", 0, keyboard_mods_list, 0, NULL },
5571 { NULL, 0, NULL, 0, NULL }
5572 };
5573
5574 static DIALOG keyboard_control_dlg[] =
5575 {
5576 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5577 { jwin_win_proc, 8, 39, 304, 240, 0, 0, 0, D_EXIT, 0, 0, (void *) "Keyboard Controls", NULL, NULL },
5578 { jwin_tab_proc, 8+4, 39+23,304-8,240-56,vc(0), vc(15), 0, 0, 0, 0, (void *) keyboard_control_tabs, NULL, (void *)keyboard_control_dlg },
5579 { d_stringloader, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5580 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5581 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5582 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5583 // Keys
5584 // 6
5585 { jwin_frame_proc, 14, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5586 { jwin_frame_proc, 158, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5587 { jwin_frame_proc, 14, 181, 292, 67, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5588 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Standard", NULL, NULL },
5589 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Extended", NULL, NULL },
5590 // 11
5591 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5592 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5593 { jwin_text_proc, 92-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5594 { jwin_text_proc, 92-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5595 { jwin_text_proc, 92-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5596 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5597 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5598 { jwin_text_proc, 237-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5599 { jwin_text_proc, 237-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5600 { jwin_text_proc, 237-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5601 // 21
5602 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Akey},
5603 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bkey},
5604 { d_kbutton_proc, 22, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Skey},
5605 { d_kbutton_proc, 22, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exkey1},
5606 { d_kbutton_proc, 22, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exkey3},
5607 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lkey},
5608 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rkey},
5609 { d_kbutton_proc, 167, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pkey},
5610 { d_kbutton_proc, 167, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exkey2},
5611 { d_kbutton_proc, 167, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exkey4},
5612 // 31
5613 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Akey},
5614 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bkey},
5615 { d_k_clearbutton_proc, 22+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Skey},
5616 { d_k_clearbutton_proc, 22+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey1},
5617 { d_k_clearbutton_proc, 22+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey3},
5618 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lkey},
5619 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rkey},
5620 { d_k_clearbutton_proc, 167+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pkey},
5621 { d_k_clearbutton_proc, 167+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey2},
5622 { d_k_clearbutton_proc, 167+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey4},
5623 // Dirs
5624 // 41
5625 { jwin_frame_proc, 14, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5626 { jwin_frame_proc, 159, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5627 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5628 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5629 // 45
5630 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5631 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5632 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5633 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5634 // 49
5635 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUkey},
5636 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDkey},
5637 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLkey},
5638 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRkey},
5639 // 53
5640 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUkey},
5641 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDkey},
5642 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLkey},
5643 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRkey},
5644 // Mods
5645 // 57
5646 { jwin_frame_proc, 14, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5647 { jwin_frame_proc, 158, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5648 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Left", NULL, NULL },
5649 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Right", NULL, NULL },
5650 // 61
5651 { jwin_text_proc, 92-26, 101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod1, NULL, NULL },
5652 { jwin_text_proc, 92-26, 129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod1, NULL, NULL },
5653 { jwin_text_proc, 237-4-22,101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod2, NULL, NULL },
5654 { jwin_text_proc, 237-4-22,129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod2, NULL, NULL },
5655 // 65
5656 { d_kbutton_proc, 22, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[0]},
5657 { d_kbutton_proc, 22, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[2]},
5658 { d_kbutton_proc, 167, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[1]},
5659 { d_kbutton_proc, 167, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[3]},
5660 // 69
5661 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[0]},
5662 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[2]},
5663 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[1]},
5664 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[3]},
5665 // 73
5666 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5667 };
5668
5669 int32_t midi_dp[3] = {0,0,0};
5670 int32_t emus_dp[3] = {2,0,0};
5671 int32_t sfx_dp[3] = {3,0,0};
5672 int32_t pan_dp[3] = {0,0,0};
5673
5674 static DIALOG sound_dlg[] =
5675 {
5676 //(dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5677 414 { jwin_win_proc, 0, 0, 320, 178, 0, 0, 0, D_EXIT, 0, 0, (void *) "Sound Settings", NULL, NULL },
5678 414 { d_stringloader, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5679 414 { jwin_button_proc, 58, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5680 414 { jwin_button_proc, 138, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5681 414 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5682 414 { jwin_frame_proc, 10, 28, 300, 112, 0, 0, 0, 0, FR_ETCHED, 0, NULL, NULL, NULL },
5683 414 { jwin_rtext_proc, 190, 40, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_a, NULL, NULL },
5684 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5685 414 { jwin_rtext_proc, 190, 56, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_l, NULL, NULL },
5686 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5687 // 10
5688 414 { jwin_rtext_proc, 190, 72, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_r, NULL, NULL },
5689 414 { jwin_rtext_proc, 190, 88, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_s, NULL, NULL },
5690 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5691 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5692 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5693 414 { jwin_slider_proc, 196, 40, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, midi_dp },
5694 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5695 414 { jwin_slider_proc, 196, 56, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, emus_dp },
5696 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5697 414 { jwin_slider_proc, 196, 72, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, sfx_dp },
5698 //20
5699 414 { jwin_slider_proc, 196, 88, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 3, 0, NULL, (void *) set_pan, pan_dp },
5700 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5701 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5702 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5703 414 { jwin_text_proc, 17, 40, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "MIDI Volume", NULL, NULL },
5704 414 { jwin_text_proc, 17, 56, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Music Volume (Enhanced Music)", NULL, NULL },
5705 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5706 414 { jwin_text_proc, 17, 72, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Volume", NULL, NULL },
5707 414 { jwin_text_proc, 17, 88, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Pan", NULL, NULL },
5708 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5709 //30
5710 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5711 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5712 414 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5713 };
5714
5715 char zc_builddate[80];
5716 char zc_aboutstr[80];
5717
5718 static DIALOG about_dlg[] =
5719 {
5720 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5721 { jwin_win_proc, 68, 52, 184, 154, 0, 0, 0, D_EXIT, 0, 0, (void *) "About", NULL, NULL },
5722 { jwin_button_proc, 140, 176, 41, 21, vc(14), 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5723 { jwin_ctext_proc, 160, 84, 0, 8, vc(0), vc(11), 0, 0, 0, 0, zc_aboutstr, NULL, NULL },
5724 { jwin_ctext_proc, 160, 92, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5725 { jwin_ctext_proc, 160, 100, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, zc_builddate, NULL, NULL },
5726 { jwin_text_proc, 88, 124, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Coded by:", NULL, NULL },
5727 { jwin_text_proc, 88, 132, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Phantom Menace", NULL, NULL },
5728 { jwin_text_proc, 88, 144, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Produced by:", NULL, NULL },
5729 { jwin_text_proc, 88, 152, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Armageddon Games", NULL, NULL },
5730 { jwin_frame_proc, 80, 117, 160, 50, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5731 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5732 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5733 };
5734
5735
5736 static DIALOG quest_dlg[] =
5737 {
5738 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5739 { jwin_win_proc, 68, 25, 184, 190, 0, 0, 0, D_EXIT, 0, 0, (void *) "Quest Info", NULL, NULL },
5740 { jwin_edit_proc, 84, 54, 152, 16, 0, 0, 0, D_READONLY, 100, 0, NULL, NULL, NULL },
5741 { jwin_text_proc, 89, 84, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
5742 { jwin_text_proc, 152, 84, 24, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5743 { jwin_text_proc, 89, 94, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Version:", NULL, NULL },
5744 { jwin_text_proc, 160, 94, 64, 8, vc(7), vc(11), 0, 0, 0, 0, header_version_nul_term, NULL, NULL },
5745 { jwin_text_proc, 89, 104, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "ZQ Version:", NULL, NULL },
5746 { jwin_text_proc, 130, 104, 64, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5747 { jwin_text_proc, 84, 126, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Title:", NULL, NULL },
5748 { jwin_textbox_proc, 84, 136, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.title, NULL, NULL },
5749 { jwin_text_proc, 84, 168, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Author:", NULL, NULL },
5750 { jwin_textbox_proc, 84, 178, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.author, NULL, NULL },
5751 { jwin_frame_proc, 84, 79, 152, 38, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5752 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5753 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5754 };
5755
5756 static DIALOG triforce_dlg[] =
5757 {
5758 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
5759 { jwin_win_proc, 72, 64, 177, 105, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Triforce Pieces", NULL, NULL },
5760 // 1
5761 { jwin_check_proc, 129, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "1", NULL, NULL },
5762 { jwin_check_proc, 129, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "2", NULL, NULL },
5763 { jwin_check_proc, 129, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "3", NULL, NULL },
5764 { jwin_check_proc, 129, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "4", NULL, NULL },
5765 { jwin_check_proc, 172, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "5", NULL, NULL },
5766 { jwin_check_proc, 172, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "6", NULL, NULL },
5767 { jwin_check_proc, 172, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "7", NULL, NULL },
5768 { jwin_check_proc, 172, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "8", NULL, NULL },
5769 // 9
5770 { jwin_button_proc, 90, 144, 61, 21, vc(0), vc(11), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
5771 { jwin_button_proc, 170, 144, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5772 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5773 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5774 };
5775
5776 int32_t onToggleRecordingNewSaves()
5777 {
5778 if (zc_get_config("zeldadx", "replay_new_saves", false))
5779 {
5780 zc_set_config("zeldadx", "replay_new_saves", false);
5781 }
5782 else
5783 {
5784 zc_set_config("zeldadx", "replay_new_saves", true);
5785 jwin_alert("Recording", "Newly created saves will be recorded and written to a replay file.",
5786 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5787 }
5788 return D_O_K;
5789 }
5790
5791 #ifdef HAS_CURL
5792 int32_t onToggleAutoUploadReplays()
5793 {
5794 if (zc_get_config("zeldadx", "replay_upload", false))
5795 {
5796 zc_set_config("zeldadx", "replay_upload", false);
5797 }
5798 else
5799 {
5800 zc_set_config("zeldadx", "replay_upload", true);
5801 jwin_alert("Replays", "Replays will be automatically uploaded. This helps development by",
5802 " preventing bugs and simplifying bug reports.",
5803 "Upload will happen no more than once a week when closing ZC",
5804 "OK",NULL,13,27,get_zc_font(font_lfont));
5805
5806 if (!zc_get_config("zeldadx", "replay_new_saves", false))
5807 onToggleRecordingNewSaves();
5808 }
5809 return D_O_K;
5810 }
5811
5812 int32_t onUploadReplays()
5813 {
5814 if(jwin_alert3(
5815 "Upload replays",
5816 "Upload your replays now to assist in development?",
5817 NULL,
5818 NULL,
5819 "&Yes",
5820 "&No",
5821 NULL,
5822 'y',
5823 'n',
5824 0,
5825 get_zc_font(font_lfont)) == 1)
5826 {
5827 int num_uploaded = replay_upload();
5828 jwin_alert("Upload replays", fmt::format("Uploaded {} replays", num_uploaded).c_str(),
5829 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5830 }
5831 return D_O_K;
5832 }
5833
5834 int32_t onClearUploadCache()
5835 {
5836 if(jwin_alert3(
5837 "Upload replays",
5838 "Clear the upload cache?",
5839 "This simply deletes replays/state.json. There's no harm in doing this, but",
5840 "likely is not necessary.",
5841 "&Yes",
5842 "&No",
5843 NULL,
5844 'y',
5845 'n',
5846 0,
5847 get_zc_font(font_lfont)) == 1)
5848 {
5849 replay_upload_clear_cache();
5850 }
5851 return D_O_K;
5852 }
5853 #endif
5854
5855 int32_t onToggleSnapshotAllFrames()
5856 {
5857 replay_set_snapshot_all_frames(!replay_is_snapshot_all_frames());
5858 return D_O_K;
5859 }
5860
5861 int32_t onStopReplayOrRecord()
5862 {
5863 if (replay_is_replaying())
5864 {
5865 replay_quit();
5866 }
5867 else if (replay_get_mode() == ReplayMode::Record)
5868 {
5869 if (!replay_get_meta_bool("test_mode"))
5870 {
5871 jwin_alert("Recording", "You cannot stop recording a save file.",
5872 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5873 return D_CLOSE;
5874 }
5875
5876 if (jwin_alert("Stop Recording",
5877 "Save replay to disk and stop recording?",
5878 "This will stop the recording.",
5879 NULL,
5880 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5881 return D_CLOSE;
5882
5883 replay_save();
5884 replay_stop();
5885 }
5886 return D_O_K;
5887 }
5888
5889 static int32_t handle_on_load_replay(ReplayMode mode)
5890 {
5891 bool ctrl = CHECK_CTRL_CMD;
5892 if (Playing)
5893 {
5894 if (jwin_alert("Replay - Warning!",
5895 "Loading a replay will exit the current game.",
5896 "All unsaved progress will be lost.",
5897 "Do you wish to continue?",
5898 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5899 return D_CLOSE;
5900 }
5901
5902 std::string mode_string = replay_mode_to_string(mode);
5903 mode_string[0] = std::toupper(mode_string[0]);
5904
5905 std::string line_1 = "Select a replay file to play back.";
5906 std::string line_2 = "You won't be able to save, and it won't effect existing saves.";
5907 std::string line_3 = "You can stop the replay and take over manually any time.";
5908 if (mode == ReplayMode::Update)
5909 {
5910 line_1 = "Select a replay file to update.";
5911 line_2 = "WARNING: be sure to back up the zplay file";
5912 line_3 = "and verify that the updated replay works as expected!";
5913 }
5914
5915 if (jwin_alert(mode_string.c_str(),
5916 line_1.c_str(),
5917 line_2.c_str(),
5918 line_3.c_str(),
5919 "OK","Nevermind",13,27,get_zc_font(font_lfont)) == 1)
5920 {
5921 std::string replay_path = "replays/";
5922 if(ctrl && devpwd())
5923 replay_path = "../../tests/replays/";
5924 std::string prompt = fmt::format("Load Replay ({})", REPLAY_EXTENSION);
5925 if (auto result = prompt_for_existing_file(prompt, REPLAY_EXTENSION, nullptr, replay_path))
5926 replay_path = *result;
5927 else
5928 return D_CLOSE;
5929
5930 replay_quit();
5931 load_replay_file_deferred(mode, replay_path);
5932 Quit = qRESET;
5933 return D_CLOSE;
5934 }
5935 return D_O_K;
5936 }
5937
5938 int32_t onLoadReplay()
5939 {
5940 return handle_on_load_replay(ReplayMode::Replay);
5941 }
5942
5943 int32_t onLoadReplayAssert()
5944 {
5945 return handle_on_load_replay(ReplayMode::Assert);
5946 }
5947
5948 int32_t onLoadReplayUpdate()
5949 {
5950 return handle_on_load_replay(ReplayMode::Update);
5951 }
5952
5953 int32_t onSaveReplay()
5954 {
5955 if (replay_get_mode() == ReplayMode::Record)
5956 {
5957 if (!replay_get_meta_bool("test_mode"))
5958 {
5959 if (jwin_alert("Save Replay",
5960 "This will save a copy of the replay up to this point.",
5961 "The official replay file will be untouched.",
5962 "Do you wish to continue?",
5963 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5964 {
5965 return D_CLOSE;
5966 }
5967
5968 std::string replay_path = replay_get_replay_path().string();
5969 std::string prompt = fmt::format("Save Replay ({})", REPLAY_EXTENSION);
5970 if (auto result = prompt_for_new_file(prompt, REPLAY_EXTENSION, nullptr, replay_path))
5971 replay_path = *result;
5972 else
5973 return D_CLOSE;
5974
5975 if (fileexists(replay_path.c_str()))
5976 {
5977 jwin_alert("Save Replay", "You cannot overwrite an existing file.",
5978 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5979 return D_CLOSE;
5980 }
5981
5982 replay_save(replay_path);
5983 }
5984 else
5985 {
5986 replay_save();
5987 }
5988 }
5989 return D_O_K;
5990 }
5991
5992 enum
5993 {
5994 MENUID_REPLAY_RECORDNEW,
5995 MENUID_REPLAY_STOP,
5996 MENUID_REPLAY_SAVE,
5997 MENUID_REPLAY_SNAP_ALL,
5998 MENUID_REPLAY_AUTOUPLOAD,
5999 MENUID_REPLAY_UPLOAD,
6000 MENUID_REPLAY_CLEARUPLOADCACHE,
6001 };
6002
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 static NewMenu replay_menu
6003 5382 {
6004
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Record new saves", onToggleRecordingNewSaves, MENUID_REPLAY_RECORDNEW },
6005
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 {},
6006
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Stop replay", onStopReplayOrRecord, MENUID_REPLAY_STOP },
6007
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Load replay", onLoadReplay },
6008
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Load replay (assert)", onLoadReplayAssert },
6009
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Load replay (update)", onLoadReplayUpdate },
6010
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Save replay", onSaveReplay, MENUID_REPLAY_SAVE },
6011
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Snapshot all frames", onToggleSnapshotAllFrames, MENUID_REPLAY_SNAP_ALL },
6012 #ifdef HAS_CURL
6013
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 {},
6014
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Auto upload replays", onToggleAutoUploadReplays, MENUID_REPLAY_AUTOUPLOAD },
6015
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Upload replays", onUploadReplays, MENUID_REPLAY_UPLOAD },
6016
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Clear upload cache", onClearUploadCache, MENUID_REPLAY_CLEARUPLOADCACHE },
6017 #endif
6018 };
6019
6020 static DIALOG credits_dlg[] =
6021 {
6022 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6023 { jwin_win_proc, 40, 38, 241, 173, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "ZQuest Classic Credits", NULL, NULL },
6024 { jwin_frame_proc, 47, 65, 227, 115, vc(15), vc(1), 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
6025 { d_bitmap_proc, 49, 67, 222, 110, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6026 { jwin_button_proc, 140, 184, 41, 21, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6027 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6028 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6029 };
6030
6031 414 static ListData dmap_list(dmaplist, &font);
6032
6033 static DIALOG goto_dlg[] =
6034 {
6035 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6036 { jwin_win_proc, 48, 25, 205, 100, 0, 0, 0, D_EXIT, 0, 0, (void *) "Goto Location", NULL, NULL },
6037 { jwin_button_proc, 90, 176-78, 61, 21, vc(14), 0, 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6038 { jwin_button_proc, 170, 176-78, 61, 21, vc(14), 0, 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6039 { jwin_text_proc, 55, 129-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
6040 { jwin_droplist_proc, 88, 126-75, 160, 16, 0, 0, 0, 0, 0, 0, (void *) &dmap_list, NULL, NULL },
6041 { jwin_text_proc, 55, 149-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Screen:", NULL, NULL },
6042 { jwin_edit_proc, 132, 146-75, 91, 16, 0, 0, 0, 0, 2, 0, NULL, NULL, NULL },
6043 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6044 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6045 };
6046
6047 int32_t onGoTo()
6048 {
6049 bool music = false;
6050 music = music;
6051 sprintf(cheat_goto_screen_str,"%X",cheat_goto_screen);
6052
6053 goto_dlg[0].dp2=get_zc_font(font_lfont);
6054 goto_dlg[4].d2=cheat_goto_dmap;
6055 goto_dlg[6].dp=cheat_goto_screen_str;
6056
6057 clear_keybuf();
6058
6059 large_dialog(goto_dlg);
6060
6061 if(do_zqdialog(goto_dlg,4)==1)
6062 {
6063 int dmap = goto_dlg[4].d2;
6064 int screen = zc_xtoi(cheat_goto_screen_str);
6065 int adjusted_screen = screen + DMaps[dmap].xoff;
6066 if (adjusted_screen < 0 || adjusted_screen >= 128)
6067 {
6068 InfoDialog("Invalid screen", fmt::format("The screen {:02X} is out of bounds.", adjusted_screen)).show();
6069 }
6070 else
6071 {
6072 cheats_enqueue(Cheat::GoTo, dmap, screen);
6073 }
6074 };
6075
6076 return D_O_K;
6077 }
6078
6079 int32_t onGoToComplete()
6080 {
6081 if(!Playing)
6082 {
6083 return D_O_K;
6084 }
6085
6086 enter_sys_pal();
6087 music_pause();
6088 pause_all_sfx();
6089 onGoTo();
6090 eat_buttons();
6091
6092 zc_readrawkey(KEY_ESC);
6093
6094 exit_sys_pal();
6095 music_resume();
6096 resume_all_sfx();
6097 return D_O_K;
6098 }
6099
6100 int32_t onCredits()
6101 {
6102 return D_O_K;
6103 }
6104
6105 const char *midilist(int32_t index, int32_t *list_size)
6106 {
6107 if(index<0)
6108 {
6109 *list_size=0;
6110
6111 for(int32_t i=0; i<MAXMIDIS; i++)
6112 if(tunes[i].data)
6113 ++(*list_size);
6114
6115 return NULL;
6116 }
6117
6118 int32_t i=0,m=0;
6119
6120 while(m<=index && i<=MAXMIDIS)
6121 {
6122 if(tunes[i].data)
6123 ++m;
6124
6125 ++i;
6126 }
6127
6128 --i;
6129
6130 if(i==MAXMIDIS && m<index)
6131 return "(null)";
6132
6133 return tunes[i].title;
6134 }
6135
6136 /* ------- MIDI info stuff -------- */
6137
6138 char *text;
6139 midi_info *zmi;
6140 bool dialog_running;
6141 bool listening;
6142
6143 void get_info(int32_t index);
6144
6145 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c)
6146 {
6147 int32_t d2 = d->d2;
6148 int32_t ret = jwin_droplist_proc(msg,d,c);
6149
6150 if(d2!=d->d2)
6151 {
6152 get_info(d->d2);
6153 }
6154
6155 return ret;
6156 }
6157
6158 int32_t d_listen_proc(int32_t msg,DIALOG *d,int32_t c)
6159 {
6160 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6161
6162 int32_t ret = jwin_button_proc(msg,d,c);
6163
6164 if(ret == D_CLOSE)
6165 {
6166 // get current midi index
6167 int32_t index = (d+(d->d1))->d2;
6168 int32_t i=0, m=0;
6169
6170 while(m<=index && i<=MAXMIDIS)
6171 {
6172 if(tunes[i].data)
6173 ++m;
6174
6175 ++i;
6176 }
6177
6178 --i;
6179 jukebox(i);
6180 listening = true;
6181 ret = D_O_K;
6182 }
6183
6184 return ret;
6185 }
6186
6187 int32_t d_savemidi_proc(int32_t msg,DIALOG *d,int32_t c)
6188 {
6189 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6190
6191 int32_t ret = jwin_button_proc(msg,d,c);
6192
6193 if(ret == D_CLOSE)
6194 {
6195 // get current midi index
6196 int32_t index = (d+(d->d1))->d2;
6197 int32_t i=0, m=0;
6198
6199 while(m<=index && i<=MAXMIDIS)
6200 {
6201 if(tunes[i].data)
6202 ++m;
6203
6204 ++i;
6205 }
6206
6207 --i;
6208
6209 char title[40] = "Save MIDI: ";
6210 static EXT_LIST list[] =
6211 {
6212 { (char *)"MIDI files (*.mid)", (char *)"mid" },
6213 { NULL, NULL }
6214 };
6215
6216 strcpy(title+11, tunes[i].title);
6217 title[39] = '\0';
6218
6219 std::string fname;
6220 if (auto result = prompt_for_new_file(title, "", list, "tune.mid"))
6221 fname = *result;
6222 else
6223 goto done;
6224
6225 if(exists(fname.c_str()))
6226 {
6227 if(jwin_alert(title, fname.c_str(), "already exists.", "Overwrite it?", "&Yes","&No",'y','n',get_zc_font(font_lfont))==2)
6228 goto done;
6229 }
6230
6231 // save midi i
6232
6233 if (save_midi(fname.c_str(), tunes[i].data) != 0)
6234 jwin_alert(title, "Error saving MIDI to", fname.c_str(), NULL, "Darn", NULL,13,27,get_zc_font(font_lfont));
6235
6236 done:
6237 chop_path(fname.data());
6238 ret = D_REDRAW;
6239 }
6240
6241 return ret;
6242 }
6243
6244 414 static ListData midi_list(midilist, &font);
6245
6246 static DIALOG midi_dlg[] =
6247 {
6248 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6249 { jwin_win_proc, 8, 28, 304, 184, 0, 0, 0, D_EXIT, 0, 0, (void *) "MIDI Info", NULL, NULL },
6250 { jwin_text_proc, 32, 60, 40, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Tune:", NULL, NULL },
6251 { d_midilist_proc, 80, 56, 192, 16, 0, 0, 0, 0, 0, 0, (void *) &midi_list, NULL, NULL },
6252 { jwin_textbox_proc, 15, 80, 290, 96, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6253 { d_listen_proc, 24, 183, 72, 21, 0, 0, 'l', D_EXIT, -2, 0, (void *) "&Listen", NULL, NULL },
6254 { d_savemidi_proc, 108, 183, 72, 21, 0, 0, 's', D_EXIT, -3, 0, (void *) "&Save", NULL, NULL },
6255 { jwin_button_proc, 236, 183, 61, 21, 0, 0, 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
6256 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6257 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6258 };
6259
6260 void get_info(int32_t index)
6261 {
6262 int32_t i=0, m=0;
6263
6264 while(m<=index && i<=MAXMIDIS)
6265 {
6266 if(tunes[i].data)
6267 ++m;
6268
6269 ++i;
6270 }
6271
6272 --i;
6273
6274 if(i==MAXMIDIS && m<index)
6275 strcpy(text,"(null)");
6276 else
6277 {
6278 get_midi_info(tunes[i].data,zmi);
6279 get_midi_text(tunes[i].data,zmi,text);
6280 }
6281
6282 midi_dlg[0].dp2=get_zc_font(font_lfont);
6283 midi_dlg[3].dp = text;
6284 midi_dlg[3].d1 = midi_dlg[3].d2 = 0;
6285 midi_dlg[5].flags = (tunes[i].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6286
6287 if(dialog_running)
6288 {
6289 jwin_textbox_proc(MSG_DRAW,midi_dlg+3,0);
6290 d_savemidi_proc(MSG_DRAW,midi_dlg+5,0);
6291 }
6292 }
6293
6294 int32_t onMIDICredits()
6295 {
6296 text = (char*)malloc(4096);
6297 zmi = (midi_info*)malloc(sizeof(midi_info));
6298
6299 if(!text || !zmi)
6300 {
6301 jwin_alert(NULL,"Not enough memory",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6302 return D_O_K;
6303 }
6304
6305 bool do_pause_midi = midi_pos >= 0 && currmidi;
6306 auto restore_midi = currmidi;
6307 if(do_pause_midi)
6308 {
6309 paused_midi_pos = midi_pos;
6310 stop_midi();
6311 midi_suspended = midissuspHALTED;
6312 }
6313
6314 midi_dlg[0].dp2=get_zc_font(font_lfont);
6315 midi_dlg[2].d1 = 0;
6316 midi_dlg[2].d2 = 0;
6317 midi_dlg[4].flags = D_EXIT;
6318 midi_dlg[5].flags = (tunes[midi_dlg[2].d1].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6319
6320 listening = false;
6321 dialog_running=false;
6322 get_info(0);
6323
6324 dialog_running=true;
6325
6326 large_dialog(midi_dlg);
6327
6328 do_zqdialog(midi_dlg,0);
6329 dialog_running=false;
6330
6331 if(listening)
6332 music_stop();
6333
6334 if(do_pause_midi)
6335 {
6336 // TODO: this probably doesn't resume midis nicely when scrolling (or in some other inner-gameloop).
6337 midi_suspended = midissuspRESUME;
6338 currmidi = restore_midi;
6339 midi_pos = paused_midi_pos;
6340 }
6341
6342 if(text) free(text);
6343 if(zmi) free(zmi);
6344 return D_O_K;
6345 }
6346
6347 int32_t onAbout()
6348 {
6349 char buf1[80]={0};
6350 std::ostringstream oss;
6351 sprintf(buf1,"ZQuest Classic Player");
6352 oss << buf1 << '\n';
6353 sprintf(buf1,"Version: %s", getVersionString());
6354 oss << buf1 << '\n';
6355 sprintf(buf1,"Build Date: %s %s, %d at @ %s %s", dayextension(BUILDTM_DAY).c_str(), (char*)months[BUILDTM_MONTH], BUILDTM_YEAR, __TIME__, __TIMEZONE__);
6356 oss << buf1 << '\n';
6357
6358 InfoDialog("About ZC", oss.str()).show();
6359 return D_O_K;
6360 }
6361
6362 int32_t onQuest()
6363 {
6364 char fname[100];
6365 strcpy(fname, get_filename(qstpath));
6366 quest_dlg[0].dp2=get_zc_font(font_lfont);
6367 quest_dlg[1].dp = fname;
6368
6369 if(QHeader.quest_number==0)
6370 sprintf(str_a,"Custom");
6371 else
6372 sprintf(str_a,"%d",QHeader.quest_number);
6373
6374 sprintf(str_s,"%s",QHeader.getVerStr());
6375
6376 quest_dlg[11].d1 = quest_dlg[9].d1 = 0;
6377 quest_dlg[11].d2 = quest_dlg[9].d2 = 0;
6378
6379 large_dialog(quest_dlg);
6380
6381 do_zqdialog(quest_dlg, 0);
6382 return D_O_K;
6383 }
6384
6385 void call_vidmode_dlg();
6386 int32_t onVidMode()
6387 {
6388 call_vidmode_dlg();
6389 return D_O_K;
6390 }
6391
6392 #define addToHash(c,b,h) if(h->find(c ## key) == h->end()) \
6393 {(*h)[c ## key]=true;} else { if ( c ## key != 0 ) b = false;}
6394 //Added an extra statement, so that if the key is cleared to 0, the cleared
6395 //keybinding status need not be unique. -Z ( 1st April, 2019 )
6396
6397 void load_ukeys(int32_t* arr)
6398 {
6399 arr[ukey_a] = Akey;
6400 arr[ukey_b] = Bkey;
6401 arr[ukey_s] = Skey;
6402 arr[ukey_l] = Lkey;
6403 arr[ukey_r] = Rkey;
6404 arr[ukey_p] = Pkey;
6405 arr[ukey_ex1] = Exkey1;
6406 arr[ukey_ex2] = Exkey2;
6407 arr[ukey_ex3] = Exkey3;
6408 arr[ukey_ex4] = Exkey4;
6409 arr[ukey_du] = DUkey;
6410 arr[ukey_dd] = DDkey;
6411 arr[ukey_dl] = DLkey;
6412 arr[ukey_dr] = DRkey;
6413 arr[ukey_mod1a] = cheat_modifier_keys[0];
6414 arr[ukey_mod1b] = cheat_modifier_keys[1];
6415 arr[ukey_mod2a] = cheat_modifier_keys[2];
6416 arr[ukey_mod2b] = cheat_modifier_keys[3];
6417 };
6418
6419 static const char* ukey_names[] = {
6420 "A", "B", "Start", "L", "R", "Map",
6421 "Ex1", "Ex2", "Ex3", "Ex4", "Up", "Down",
6422 "Left", "Right", "Cheat Mod L1", "Cheat Mod L2",
6423 "Cheat Mod R1", "Cheat Mod R2",
6424 };
6425 std::string get_ukey_name(int32_t k)
6426 {
6427 if (k < num_ukey) return ukey_names[k];
6428 return "";
6429 }
6430
6431 int32_t onKeyboard()
6432 {
6433 int32_t a = Akey;
6434 int32_t b = Bkey;
6435 int32_t s = Skey;
6436 int32_t l = Lkey;
6437 int32_t r = Rkey;
6438 int32_t p = Pkey;
6439 int32_t ex1 = Exkey1;
6440 int32_t ex2 = Exkey2;
6441 int32_t ex3 = Exkey3;
6442 int32_t ex4 = Exkey4;
6443 int32_t du = DUkey;
6444 int32_t dd = DDkey;
6445 int32_t dl = DLkey;
6446 int32_t dr = DRkey;
6447 int32_t mod1a = cheat_modifier_keys[0];
6448 int32_t mod1b = cheat_modifier_keys[1];
6449 int32_t mod2a = cheat_modifier_keys[2];
6450 int32_t mod2b = cheat_modifier_keys[3];
6451 bool done=false;
6452 int32_t ret;
6453
6454 keyboard_control_dlg[0].dp2=get_zc_font(font_lfont);
6455
6456 large_dialog(keyboard_control_dlg);
6457
6458 while(!done)
6459 {
6460 ret = do_zqdialog(keyboard_control_dlg,3);
6461
6462 if(ret==3) // OK
6463 {
6464 int32_t ukeys[num_ukey];
6465 load_ukeys(ukeys);
6466 std::vector<std::string> uniqueError;
6467 for(int32_t q = 0; q < num_ukey; ++q)
6468 {
6469 for(int32_t p = q+1; p < num_ukey; ++p)
6470 {
6471 if(ukeys[q] == ukeys[p] && ukeys[q] != 0)
6472 {
6473 char buf[64];
6474 sprintf(buf, "'%s' conflicts with '%s'", get_ukey_name(q).c_str(), get_ukey_name(p).c_str());
6475 std::string str(buf);
6476 uniqueError.push_back(str);
6477 }
6478 }
6479 }
6480 if(uniqueError.size() == 0)
6481 {
6482 done = true;
6483 save_control_configs(true);
6484 }
6485 else
6486 {
6487 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, keyboard_control_dlg[0].w,keyboard_control_dlg[0].h, 2);
6488 box_out("Cannot have duplicate keybinds!"); box_eol();
6489 for(std::vector<std::string>::iterator it = uniqueError.begin();
6490 it != uniqueError.end(); ++it)
6491 {
6492 box_out((*it).c_str()); box_eol();
6493 }
6494 box_end(true);
6495 }
6496 }
6497 else // Cancel
6498 {
6499 Akey = a;
6500 Bkey = b;
6501 Skey = s;
6502 Lkey = l;
6503 Rkey = r;
6504 Pkey = p;
6505 Exkey1 = ex1;
6506 Exkey2 = ex2;
6507 Exkey3 = ex3;
6508 Exkey4 = ex4;
6509 DUkey = du;
6510 DDkey = dd;
6511 DLkey = dl;
6512 DRkey = dr;
6513 cheat_modifier_keys[0] = mod1a;
6514 cheat_modifier_keys[1] = mod1b;
6515 cheat_modifier_keys[2] = mod2a;
6516 cheat_modifier_keys[3] = mod2b;
6517
6518 done=true;
6519 }
6520
6521 rest(1);
6522 }
6523
6524 return D_O_K;
6525 }
6526
6527 int32_t onGamepad()
6528 {
6529 if (al_get_num_joysticks() == 0)
6530 {
6531 InfoDialog("ZC", "No gamepads detected.").show();
6532 return D_O_K;
6533 }
6534
6535 int32_t a = Abtn;
6536 int32_t b = Bbtn;
6537 int32_t s = Sbtn;
6538 int32_t l = Lbtn;
6539 int32_t r = Rbtn;
6540 int32_t m = Mbtn;
6541 int32_t p = Pbtn;
6542 int32_t ex1 = Exbtn1;
6543 int32_t ex2 = Exbtn2;
6544 int32_t ex3 = Exbtn3;
6545 int32_t ex4 = Exbtn4;
6546 int32_t up = DUbtn;
6547 int32_t down = DDbtn;
6548 int32_t left = DLbtn;
6549 int32_t right = DRbtn;
6550 int32_t joy = joystick_index;
6551 int32_t stick_1 = js_stick_1_x_stick;
6552 int32_t stick_2 = js_stick_2_x_stick;
6553
6554 gamepad_dlg[0].dp2=get_zc_font(font_lfont);
6555 if(analog_movement)
6556 gamepad_dlg[56].flags|=D_SELECTED;
6557 else
6558 gamepad_dlg[56].flags&=~D_SELECTED;
6559
6560 // TODO: should use controller device GUID or name instead of index, otherwise this value is not
6561 // consistent unless exact same number of joysticks is always connected. Name is problematic b/c
6562 // xinput driver doesn't actually get a name (at least, doesn't for my Xbox controller).
6563 // TODO: should store gamepad control mappings per-controller, otherwise switching joystick
6564 // requires remapping every time.
6565 if (joystick_index >= al_get_num_joysticks())
6566 joystick_index = 0;
6567 gamepad_dlg[61].d2 = joystick_index;
6568
6569 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6570 if (!gamepad_dlg_cur_joystick)
6571 {
6572 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6573 return D_CLOSE;
6574 }
6575
6576 large_dialog(gamepad_dlg);
6577
6578 int32_t ret = do_zqdialog(gamepad_dlg,4);
6579
6580 if(ret == 4) //OK
6581 {
6582 analog_movement = gamepad_dlg[56].flags&D_SELECTED;
6583 joystick_index = gamepad_dlg[61].d2;
6584 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6585 if (!gamepad_dlg_cur_joystick)
6586 {
6587 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6588 return D_CLOSE;
6589 }
6590 js_stick_1_y_stick = js_stick_1_x_stick;
6591 js_stick_2_y_stick = js_stick_2_x_stick;
6592 save_control_configs(false);
6593 }
6594 else //Cancel
6595 {
6596 Abtn = a;
6597 Bbtn = b;
6598 Sbtn = s;
6599 Lbtn = l;
6600 Rbtn = r;
6601 Mbtn = m;
6602 Pbtn = p;
6603 Exbtn1 = ex1;
6604 Exbtn2 = ex2;
6605 Exbtn3 = ex3;
6606 Exbtn4 = ex4;
6607 DUbtn = up;
6608 DDbtn = down;
6609 DLbtn = left;
6610 DRbtn = right;
6611 joystick_index = joy;
6612 js_stick_1_x_stick = stick_1;
6613 js_stick_2_x_stick = stick_2;
6614 }
6615
6616 return D_O_K;
6617 }
6618
6619 int32_t onCheatKeys()
6620 {
6621 int32_t oldcheats[Cheat::Last][2];
6622 memcpy(oldcheats, cheatkeys, sizeof(cheatkeys));
6623
6624 bool done=false;
6625
6626 while(!done)
6627 {
6628 bool confirm = false;
6629 CheatKeysDialog(&confirm).show();
6630 if(confirm) // OK
6631 {
6632 std::vector<std::string> uniqueError;
6633 char buf[512];
6634 for(size_t q = 1; q < Cheat::Last; ++q)
6635 {
6636 if(cheatkeys[q][1] && !cheatkeys[q][0])
6637 {
6638 cheatkeys[q][0] = cheatkeys[q][1];
6639 cheatkeys[q][1] = 0;
6640 }
6641 }
6642 for(size_t q = 1; q < Cheat::Last; ++q)
6643 {
6644 if(!bindable_cheat((Cheat)q)) continue;
6645 for(size_t p = q+1; p < Cheat::Last; ++p)
6646 {
6647 if(!bindable_cheat((Cheat)p)) continue;
6648 for(size_t q2 = 0; q2 <= 1; ++q2)
6649 for(size_t p2 = 0; p2 <= 1; ++p2)
6650 {
6651 if(cheatkeys[q][q2] == cheatkeys[p][p2] && cheatkeys[q][q2] != 0)
6652 {
6653 uniqueError.push_back(fmt::format("'{}' ({}) conflicts with '{}' ({}) - both '{}'",
6654 cheat_to_string((Cheat)q), q2?"Alt":"Main",
6655 cheat_to_string((Cheat)p), p2?"Alt":"Main",
6656 get_keystr(cheatkeys[q][q2])));
6657 }
6658 }
6659 }
6660 }
6661 if(uniqueError.size() == 0)
6662 {
6663 done = true;
6664 save_cheatkeys();
6665 }
6666 else
6667 {
6668 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, 500,400, 2);
6669 box_out("Cannot have duplicate keybinds!"); box_eol();
6670 for(std::vector<std::string>::iterator it = uniqueError.begin();
6671 it != uniqueError.end(); ++it)
6672 {
6673 box_out((*it).c_str()); box_eol();
6674 }
6675 box_end(true);
6676 }
6677 }
6678 else // Cancel
6679 {
6680 memcpy(cheatkeys, oldcheats, sizeof(cheatkeys));
6681 done=true;
6682 }
6683 rest(1);
6684 }
6685
6686 return D_O_K;
6687 }
6688
6689 int32_t onSound()
6690 {
6691 if (get_qr(qr_OLD_SCRIPT_VOLUME))
6692 {
6693 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
6694 {
6695 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
6696 }
6697 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
6698 {
6699 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
6700 }
6701 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
6702 {
6703 emusic_volume = (int32_t)FFCore.usr_music_volume;
6704 }
6705 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
6706 {
6707 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
6708 }
6709 }
6710 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
6711 {
6712 pan_style = (int32_t)FFCore.usr_panstyle;
6713 }
6714
6715 int32_t m = midi_volume;
6716 int32_t e = emusic_volume;
6717 int32_t s = sfx_volume;
6718 int32_t p = pan_style;
6719 pan_style = vbound(pan_style,0,3);
6720
6721 sound_dlg[0].dp2=get_zc_font(font_lfont);
6722
6723 large_dialog(sound_dlg);
6724
6725 midi_dp[1] = sound_dlg[6].x;
6726 midi_dp[2] = sound_dlg[6].y;
6727 emus_dp[1] = sound_dlg[8].x;
6728 emus_dp[2] = sound_dlg[8].y;
6729 sfx_dp[1] = sound_dlg[10].x;
6730 sfx_dp[2] = sound_dlg[10].y;
6731 pan_dp[1] = sound_dlg[11].x;
6732 pan_dp[2] = sound_dlg[11].y;
6733 sound_dlg[15].d2 = (midi_volume==255) ? 32 : midi_volume>>3;
6734 sound_dlg[17].d2 = (emusic_volume==255) ? 32 : emusic_volume>>3;
6735 sound_dlg[19].d2 = (sfx_volume==255) ? 32 : sfx_volume>>3;
6736 sound_dlg[20].d2 = pan_style;
6737
6738 int32_t ret = do_zqdialog(sound_dlg,1);
6739
6740 if(ret==2)
6741 {
6742 master_volume(digi_volume,midi_volume);
6743 if (zcmusic)
6744 zcmusic_set_volume(zcmusic, emusic_volume);
6745
6746 int32_t temp_volume = sfx_volume;
6747 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
6748 temp_volume = (sfx_volume * FFCore.usr_sfx_volume) / 10000 / 100;
6749 for(int32_t i=0; i<WAV_COUNT; ++i)
6750 {
6751 if(sfx_voice[i] >= 0)
6752 voice_set_volume(sfx_voice[i], temp_volume);
6753 }
6754 zc_set_config(sfx_sect,"midi",midi_volume);
6755 zc_set_config(sfx_sect,"sfx",sfx_volume);
6756 zc_set_config(sfx_sect,"emusic",emusic_volume);
6757 zc_set_config(sfx_sect,"pan",pan_style);
6758 }
6759 else
6760 {
6761 midi_volume = m;
6762 emusic_volume = e;
6763 sfx_volume = s;
6764 pan_style = p;
6765 }
6766
6767 return D_O_K;
6768 }
6769
6770 int32_t queding(char const* s1, char const* s2, char const* s3)
6771 {
6772 return jwin_alert("ZQuest Classic",s1,s2,s3,"&Yes","&No",'y','n',get_zc_font(font_lfont));
6773 }
6774
6775 int32_t onQuit()
6776 {
6777 if(Playing)
6778 {
6779 int32_t ret=0;
6780
6781 if(get_qr(qr_NOCONTINUE))
6782 {
6783 if(standalone_mode)
6784 {
6785 ret=queding("End current game?",
6786 "The continue screen is disabled; the game",
6787 "will be reloaded from the last save.");
6788 }
6789 else
6790 {
6791 ret=queding("End current game?",
6792 "The continue screen is disabled. You will",
6793 "be returned to the file select screen.");
6794 }
6795 }
6796 else
6797 ret=queding("End current game?",NULL,NULL);
6798
6799 if(ret==1)
6800 {
6801 disableClickToFreeze=false;
6802 Quit=qQUIT;
6803
6804 // Trying to evade a door repair charge?
6805 if(repaircharge)
6806 {
6807 game->change_drupy(-repaircharge);
6808 repaircharge=0;
6809 }
6810
6811 return D_CLOSE;
6812 }
6813 }
6814
6815 return D_O_K;
6816 }
6817
6818 int32_t onTryQuitMenu()
6819 {
6820 return onTryQuit(true);
6821 }
6822
6823 int32_t onTryQuit(bool inMenu)
6824 {
6825 if(Playing && !(GameFlags & GAMEFLAG_NO_F6))
6826 {
6827 if(active_cutscene.can_f6())
6828 {
6829 if(get_qr(qr_OLD_F6))
6830 {
6831 if(inMenu) onQuit();
6832 else /*if(!get_qr(qr_NOCONTINUE))*/ f_Quit(qQUIT);
6833 }
6834 else
6835 {
6836 disableClickToFreeze=false;
6837 GameFlags |= GAMEFLAG_TRYQUIT;
6838 }
6839 return D_CLOSE;
6840 }
6841 else active_cutscene.error();
6842 }
6843
6844 return D_O_K;
6845 }
6846
6847 int32_t onReset()
6848 {
6849 if(queding(" Reset system? ",NULL,NULL)==1)
6850 {
6851 disableClickToFreeze=false;
6852 Quit=qRESET;
6853 replay_quit();
6854 return D_CLOSE;
6855 }
6856
6857 return D_O_K;
6858 }
6859
6860 int32_t onExit()
6861 {
6862 if(queding(" Quit ZQuest Classic? ",NULL,NULL)==1)
6863 {
6864 Quit=qEXIT;
6865 return D_CLOSE;
6866 }
6867
6868 return D_O_K;
6869 }
6870
6871 int32_t onDebug()
6872 {
6873 if(debug_enabled)
6874 set_debug(!get_debug());
6875 return D_O_K;
6876 }
6877
6878 int32_t onHeartBeep()
6879 {
6880 heart_beep=!heart_beep;
6881 zc_set_config(cfg_sect,"heart_beep",heart_beep);
6882 return D_O_K;
6883 }
6884
6885 int32_t onSaveIndicator()
6886 {
6887 use_save_indicator = use_save_indicator ? 0 : 1;
6888 zc_set_config(cfg_sect,"save_indicator",use_save_indicator);
6889 return D_O_K;
6890 }
6891
6892 int32_t onEpilepsy()
6893 {
6894 if(jwin_alert3(
6895 "Epilepsy Flash Reduction",
6896 "Enabling this will reduce the intensity of flashing and screen wave effects.",
6897 "Disabling this will restore standard flash and wavy behaviour.",
6898 "Proceed?",
6899 "&Yes",
6900 "&No",
6901 NULL,
6902 'y',
6903 'n',
6904 0,
6905 get_zc_font(font_lfont)) == 1)
6906 {
6907 epilepsyFlashReduction = epilepsyFlashReduction ? 0 : 1;
6908 zc_set_config(cfg_sect,"epilepsy_flash_reduction",epilepsyFlashReduction);
6909 }
6910 return D_O_K;
6911 }
6912
6913 bool rc = false;
6914
6915 static DIALOG getnum_dlg[] =
6916 {
6917 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
6918 { jwin_win_proc, 80, 80, 160, 72, vc(0), vc(11), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
6919 { jwin_text_proc, 104, 104+4, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
6920 { jwin_edit_proc, 168, 104, 48, 16, 0, 0, 0, 0, 6, 0, NULL, NULL, NULL },
6921 { jwin_button_proc, 90, 126, 61, 21, vc(0), vc(11), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6922 { jwin_button_proc, 170, 126, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6923 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6924 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6925 };
6926
6927 int32_t getnumber(const char *prompt,int32_t initialval)
6928 {
6929 char buf[20];
6930 sprintf(buf,"%d",initialval);
6931 getnum_dlg[0].dp=(void *)prompt;
6932 getnum_dlg[0].dp2=get_zc_font(font_lfont);
6933 getnum_dlg[2].dp=buf;
6934
6935 large_dialog(getnum_dlg);
6936
6937 if(do_zqdialog(getnum_dlg,2)==3)
6938 return atoi(buf);
6939
6940 return initialval;
6941 }
6942
6943 int32_t onLife()
6944 {
6945 int value = vbound(getnumber("Life",game->get_life()),1,game->get_maxlife());
6946 cheats_enqueue(Cheat::Life, value);
6947 return D_O_K;
6948 }
6949
6950 int32_t onHeartC()
6951 {
6952 int max_life = vbound(getnumber("Heart Containers",game->get_maxlife()/game->get_hp_per_heart()),1,4095) * game->get_hp_per_heart();
6953 int life = vbound(getnumber("Life",game->get_life()/game->get_hp_per_heart()),1,max_life/game->get_hp_per_heart())*game->get_hp_per_heart();
6954 cheats_enqueue(Cheat::MaxLife, max_life);
6955 cheats_enqueue(Cheat::Life, life);
6956 return D_O_K;
6957 }
6958
6959 int32_t onMagicC()
6960 {
6961 int max_magic = vbound(getnumber("Magic Containers",game->get_maxmagic()/game->get_mp_per_block()),0,2047) * game->get_mp_per_block();
6962 int magic = vbound(getnumber("Magic",game->get_magic()/game->get_mp_per_block()),0,max_magic/game->get_mp_per_block())*game->get_mp_per_block();
6963 cheats_enqueue(Cheat::MaxMagic, max_magic);
6964 cheats_enqueue(Cheat::Magic, magic);
6965 return D_O_K;
6966 }
6967
6968 int32_t onRupies()
6969 {
6970 int value = vbound(getnumber("Rupees",game->get_rupies()),0,game->get_maxcounter(1));
6971 cheats_enqueue(Cheat::Rupies, value);
6972 return D_O_K;
6973 }
6974
6975 int32_t onMaxBombs()
6976 {
6977 int value = vbound(getnumber("Max Bombs",game->get_maxbombs()),0,0xFFFF);
6978 cheats_enqueue(Cheat::MaxBombs, value);
6979 cheats_enqueue(Cheat::Bombs, value);
6980 return D_O_K;
6981 }
6982
6983 int32_t onRefillLife()
6984 {
6985 cheats_enqueue(Cheat::Life, game->get_maxlife());
6986 return D_O_K;
6987 }
6988 int32_t onRefillMagic()
6989 {
6990 cheats_enqueue(Cheat::Magic, game->get_maxmagic());
6991 return D_O_K;
6992 }
6993 int32_t onClock()
6994 {
6995 cheats_enqueue(Cheat::Clock);
6996 return D_O_K;
6997 }
6998
6999 int32_t onQstPath()
7000 {
7001 char initial_path[2048];
7002 chop_path(qstdir);
7003 strcpy(initial_path, qstdir);
7004
7005 if (auto result = prompt_for_existing_folder("Quest File Directory", initial_path, "qst"))
7006 {
7007 char* path = result->data();
7008 chop_path(path);
7009 fix_filename_case(path);
7010 fix_filename_slashes(path);
7011 strcpy(qstdir,path);
7012 strcpy(qstpath,qstdir);
7013 zc_set_config("zeldadx","quest_dir",qstdir);
7014 flush_config_file();
7015 }
7016
7017 return D_O_K;
7018 }
7019
7020 #include "dialog/cheat_dialog.h"
7021 int32_t onCheat()
7022 {
7023 call_setcheat_dialog();
7024 game->set_cheat(maxcheat);
7025 if(cheat) game->did_cheat(true);
7026 return D_O_K;
7027 }
7028
7029 int32_t onCheatRupies()
7030 {
7031 cheats_enqueue(Cheat::Rupies, game->get_maxcounter(1));
7032 return D_O_K;
7033 }
7034
7035 int32_t onCheatArrows()
7036 {
7037 cheats_enqueue(Cheat::Arrows, game->get_maxarrows());
7038 return D_O_K;
7039 }
7040
7041 int32_t onCheatBombs()
7042 {
7043 cheats_enqueue(Cheat::Bombs, game->get_maxbombs(), game->get_maxcounter(6));
7044 return D_O_K;
7045 }
7046
7047 // *** screen saver
7048
7049 18519801 int32_t after_time()
7050 {
7051
1/2
✓ Branch 0 taken 18519801 times.
✗ Branch 1 not taken.
18519801 if(ss_enable == 0)
7052 return INT_MAX;
7053
7054
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18519801 times.
18519801 if(ss_after <= 0)
7055 return 5 * 60;
7056
7057
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18519801 times.
18519801 if(ss_after <= 3)
7058 return ss_after * 15 * 60;
7059
7060
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18519801 times.
18519801 if(ss_after <= 13)
7061 return (ss_after - 3) * 60 * 60;
7062
7063 18519801 return MAX_IDLE + 1;
7064 18519801 }
7065
7066 static const char *after_str[15] =
7067 {
7068 " 5 sec", "15 sec", "30 sec", "45 sec", " 1 min", " 2 min", " 3 min",
7069 " 4 min", " 5 min", " 6 min", " 7 min", " 8 min", " 9 min", "10 min",
7070 "Never"
7071 };
7072
7073 const char *after_list(int32_t index, int32_t *list_size)
7074 {
7075 if(index < 0)
7076 {
7077 *list_size = 15;
7078 return NULL;
7079 }
7080
7081 return after_str[index];
7082 }
7083
7084 414 static ListData after__list(after_list, &font);
7085
7086 static DIALOG scrsaver_dlg[] =
7087 {
7088 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
7089 414 { jwin_win_proc, 32, 64, 256, 136, 0, 0, 0, D_EXIT, 0, 0, (void *) "Screen Saver Settings", NULL, NULL },
7090 414 { jwin_frame_proc, 42, 92, 236, 70, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
7091 414 { jwin_text_proc, 60, 104, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Run After", NULL, NULL },
7092 414 { jwin_text_proc, 60, 128, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Speed", NULL, NULL },
7093 414 { jwin_text_proc, 60, 144, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Density", NULL, NULL },
7094 414 { jwin_droplist_proc, 144, 100, 96, 16, 0, 0, 0, 0, 0, 0, (void *) &after__list, NULL, NULL },
7095 414 { jwin_slider_proc, 144, 128, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7096 414 { jwin_slider_proc, 144, 144, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7097 414 { jwin_button_proc, 42, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
7098 414 { jwin_button_proc, 124, 170, 72, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Preview", NULL, NULL },
7099 414 { jwin_button_proc, 218, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
7100 414 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
7101 414 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
7102 };
7103
7104 int32_t onScreenSaver()
7105 {
7106 scrsaver_dlg[0].dp2=get_zc_font(font_lfont);
7107 int32_t oldcfgs[3];
7108 scrsaver_dlg[5].d1 = scrsaver_dlg[5].d2 = oldcfgs[0] = ss_after;
7109 scrsaver_dlg[6].d2 = oldcfgs[1] = ss_speed;
7110 scrsaver_dlg[7].d2 = oldcfgs[2] = ss_density;
7111
7112 large_dialog(scrsaver_dlg);
7113
7114 int32_t ret = do_zqdialog(scrsaver_dlg,-1);
7115
7116 if(ret == 8 || ret == 9)
7117 {
7118 ss_after = scrsaver_dlg[5].d1;
7119 ss_speed = scrsaver_dlg[6].d2;
7120 ss_density = scrsaver_dlg[7].d2;
7121 if(oldcfgs[0] != ss_after)
7122 zc_set_config(cfg_sect,"ss_after",ss_after);
7123 if(oldcfgs[1] != ss_speed)
7124 zc_set_config(cfg_sect,"ss_speed",ss_speed);
7125 if(oldcfgs[2] != ss_density)
7126 zc_set_config(cfg_sect,"ss_density",ss_density);
7127 }
7128
7129 if(ret == 9)
7130 // preview Screen Saver
7131 {
7132 clear_keybuf();
7133 Matrix(ss_speed, ss_density, 30);
7134 system_pal(true);
7135 sys_mouse();
7136 }
7137
7138 return D_O_K;
7139 }
7140
7141 /***** Menus *****/
7142
7143 enum
7144 {
7145 MENUID_GAME_LOADQUEST,
7146 MENUID_GAME_ENDGAME,
7147 };
7148
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 static NewMenu game_menu
7149 3312 {
7150
3/6
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
414 { "&Continue","ESC", onContinue },
7151
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 {},
7152
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "L&oad Quest...", onCustomGame, MENUID_GAME_LOADQUEST },
7153
3/6
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
414 { "&End Game","F6", onTryQuitMenu, MENUID_GAME_ENDGAME },
7154
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 {},
7155 #ifdef __EMSCRIPTEN__
7156 { "&Reset","F7", onReset },
7157 #elif defined(ALLEGRO_MACOSX)
7158 { "&Reset","F7", onReset },
7159 { "&Quit","F8", onExit },
7160 #else
7161
3/6
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
414 { "&Reset","F9", onReset },
7162
3/6
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
414 { "&Quit","F10", onExit },
7163 #endif
7164 };
7165
7166
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 static NewMenu snapshot_format_menu
7167 2898 {
7168
4/8
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 414 times.
✗ Branch 7 not taken.
414 { "&BMP", std::bind(onSetSnapshotFormat, ssfmtBMP) },
7169
4/8
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 414 times.
✗ Branch 7 not taken.
414 { "&GIF", std::bind(onSetSnapshotFormat, ssfmtGIF) },
7170
4/8
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 414 times.
✗ Branch 7 not taken.
414 { "&JPG", std::bind(onSetSnapshotFormat, ssfmtJPG) },
7171
4/8
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 414 times.
✗ Branch 7 not taken.
414 { "&PNG", std::bind(onSetSnapshotFormat, ssfmtPNG) },
7172
4/8
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 414 times.
✗ Branch 7 not taken.
414 { "PC&X", std::bind(onSetSnapshotFormat, ssfmtPCX) },
7173
4/8
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 414 times.
✗ Branch 7 not taken.
414 { "&TGA", std::bind(onSetSnapshotFormat, ssfmtTGA) },
7174 };
7175
7176
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 static NewMenu bottom_8_pixels_menu
7177 1656 {
7178
4/8
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 414 times.
✗ Branch 7 not taken.
414 { "&Default (qst)", std::bind(onSetBottom8Pixels, 0) },
7179
4/8
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 414 times.
✗ Branch 7 not taken.
414 { "&On", std::bind(onSetBottom8Pixels, 1) },
7180
4/8
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 414 times.
✗ Branch 7 not taken.
414 { "&Off", std::bind(onSetBottom8Pixels, 2) },
7181 };
7182
7183
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 static NewMenu controls_menu
7184 1656 {
7185
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Key&board...", onKeyboard },
7186
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Gamepad...", onGamepad },
7187
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Cheat Keys...", onCheatKeys },
7188 };
7189
7190
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 static NewMenu name_entry_mode_menu
7191 1656 {
7192
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Keyboard", onKeyboardEntry },
7193
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Letter Grid", onLetterGridEntry },
7194
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Extended Letter Grid", onExtLetterGridEntry },
7195 };
7196
7197 static void set_controls_menu_active()
7198 {
7199
7200 }
7201
7202 enum
7203 {
7204 MENUID_WINDOW_LOCK_ASPECT,
7205 MENUID_WINDOW_LOCK_INTSCALE,
7206 MENUID_WINDOW_SAVE_SIZE,
7207 MENUID_WINDOW_SAVE_POS,
7208 MENUID_WINDOW_STRETCH,
7209 };
7210
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 static NewMenu window_menu
7211 2484 {
7212
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Lock Aspect Ratio", onDragAspect, MENUID_WINDOW_LOCK_ASPECT },
7213
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Lock Integer Scale", onIntegerScaling, MENUID_WINDOW_LOCK_INTSCALE },
7214
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Save Size Changes", onSaveDragResize, MENUID_WINDOW_SAVE_SIZE },
7215
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Save Position Changes", onWinPosSave, MENUID_WINDOW_SAVE_POS },
7216
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Stretch Game Area", onStretchGame, MENUID_WINDOW_STRETCH },
7217 };
7218 void call_zc_options_dlg();
7219 enum
7220 {
7221 MENUID_OPTIONS_PAUSE_BG,
7222 MENUID_OPTIONS_EPILEPSYPROT,
7223 MENUID_OPTIONS_SHOWBOTTOMPIXELS,
7224 };
7225
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 static NewMenu options_menu
7226 3312 {
7227
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Name &Entry Mode", &name_entry_mode_menu },
7228
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "S&napshot Format", &snapshot_format_menu },
7229
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Window Settings", &window_menu },
7230
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Epilepsy Flash Reduction", onEpilepsy, MENUID_OPTIONS_EPILEPSYPROT },
7231
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Pause In Background", onPauseInBackground, MENUID_OPTIONS_PAUSE_BG },
7232
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Show Bottom 8 Pixels", &bottom_8_pixels_menu, MENUID_OPTIONS_SHOWBOTTOMPIXELS },
7233
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "More Options", call_zc_options_dlg },
7234 };
7235 enum
7236 {
7237 MENUID_SETTINGS_CONTROLS,
7238 MENUID_SETTINGS_CAPFPS,
7239 MENUID_SETTINGS_SHOWFPS,
7240 MENUID_SETTINGS_SHOWTIME,
7241 MENUID_SETTINGS_CLICK_FREEZE,
7242 MENUID_SETTINGS_TRANSLAYERS,
7243 MENUID_SETTINGS_NESQUIT,
7244 MENUID_SETTINGS_VOLKEYS,
7245 MENUID_SETTINGS_HEARTBEEP,
7246 MENUID_SETTINGS_SAVEINDICATOR,
7247 MENUID_SETTINGS_DEBUG,
7248 };
7249
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 static NewMenu settings_menu
7250 7038 {
7251
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Sound...", onSound },
7252
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "C&ontrols", &controls_menu, MENUID_SETTINGS_CONTROLS },
7253
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 {},
7254
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Options", &options_menu },
7255
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 {},
7256
3/6
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
414 { "&Cap FPS","F1", onThrottleFPS, MENUID_SETTINGS_CAPFPS },
7257
3/6
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
414 { "Show &FPS","F2", onShowFPS, MENUID_SETTINGS_SHOWFPS },
7258
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Show &Time", onShowTime, MENUID_SETTINGS_SHOWTIME },
7259
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Click to Freeze", onClickToFreeze, MENUID_SETTINGS_CLICK_FREEZE },
7260
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Cont. &Heart Beep", onHeartBeep, MENUID_SETTINGS_HEARTBEEP },
7261
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Show Trans. &Layers", onTransLayers, MENUID_SETTINGS_TRANSLAYERS },
7262
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Up+A+B To &Quit", onNESquit, MENUID_SETTINGS_NESQUIT },
7263
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Volume &Keys", onVolKeys, MENUID_SETTINGS_VOLKEYS },
7264
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Sa&ve Indicator", onSaveIndicator, MENUID_SETTINGS_SAVEINDICATOR },
7265
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 {},
7266
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Debu&g", onDebug, MENUID_SETTINGS_DEBUG },
7267 };
7268
7269 enum
7270 {
7271 MENUID_MISC_FULLSCREEN,
7272 MENUID_MISC_VIDMODE,
7273 MENUID_MISC_QUEST_INFO,
7274 MENUID_MISC_QUEST_DIR,
7275 MENUID_MISC_CONSOLE,
7276 MENUID_MISC_CLEAR_CONSOLE_ON_LOAD,
7277 };
7278
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 static NewMenu misc_menu
7279 6210 {
7280
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&About...", onAbout },
7281 // TODO: re-enable, but: 1) do not use a bitmap thing that is hard to update 2) update names and 3) don't use the Z-word.
7282 // { "&Credits...", onCredits },
7283
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Fullscreen", onFullscreenMenu, MENUID_MISC_FULLSCREEN },
7284
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Video Mode...", onVidMode, MENUID_MISC_VIDMODE },
7285
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 {},
7286
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Quest Info...", onQuest, MENUID_MISC_QUEST_INFO },
7287
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Quest &MIDI Info...", onMIDICredits },
7288
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Quest &Directory...", onQstPath, MENUID_MISC_QUEST_DIR },
7289
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 {},
7290
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Take &Snapshot F12", onSnapshot },
7291
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Sc&reen Saver...", onScreenSaver },
7292
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Save ZC Configuration", OnSaveZCConfig },
7293
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Show Console", onConsole, MENUID_MISC_CONSOLE },
7294
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Clear Console on Qst Load", onClrConsoleOnLoad, MENUID_MISC_CLEAR_CONSOLE_ON_LOAD },
7295
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Clear Directory Cache", OnnClearQuestDir },
7296 };
7297
7298 enum
7299 {
7300 MENUID_REFILL_ARROWS,
7301 };
7302
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 static NewMenu refill_menu
7303 2484 {
7304
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Life", onRefillLife },
7305
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Magic", onRefillMagic },
7306
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Bombs", onCheatBombs },
7307
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Rupees", onCheatRupies },
7308
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Arrows", onCheatArrows, MENUID_REFILL_ARROWS },
7309 };
7310
7311 enum
7312 {
7313 MENUID_SHOW_L0,
7314 MENUID_SHOW_L1,
7315 MENUID_SHOW_L2,
7316 MENUID_SHOW_L3,
7317 MENUID_SHOW_L4,
7318 MENUID_SHOW_L5,
7319 MENUID_SHOW_L6,
7320 MENUID_SHOW_OVER,
7321 MENUID_SHOW_PUSH,
7322 MENUID_SHOW_FFC,
7323 MENUID_SHOW_SPR,
7324 MENUID_SHOW_SCRIPTNAME,
7325 MENUID_SHOW_SOLIDITY,
7326 MENUID_SHOW_HITBOX,
7327 MENUID_SHOW_EFFECT,
7328 };
7329
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 static NewMenu show_menu
7330 7866 {
7331
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Combos", onShowLayer0, MENUID_SHOW_L0 },
7332
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Layer 1", onShowLayer1, MENUID_SHOW_L1 },
7333
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Layer 2", onShowLayer2, MENUID_SHOW_L2 },
7334
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Layer 3", onShowLayer3, MENUID_SHOW_L3 },
7335
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Layer 4", onShowLayer4, MENUID_SHOW_L4 },
7336
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Layer 5", onShowLayer5, MENUID_SHOW_L5 },
7337
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Layer 6", onShowLayer6, MENUID_SHOW_L6 },
7338
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Overhead Combos", onShowLayerO, MENUID_SHOW_OVER },
7339
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Push Blocks", onShowLayerP, MENUID_SHOW_PUSH },
7340
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Freeform Combos", onShowLayerF, MENUID_SHOW_FFC },
7341
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Sprites", onShowLayerS, MENUID_SHOW_SPR },
7342
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 {},
7343
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Current FFC Scripts", onShowFFScripts, MENUID_SHOW_SCRIPTNAME },
7344
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 {},
7345
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Walkability", onShowLayerW, MENUID_SHOW_SOLIDITY },
7346
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Hitboxes", onShowHitboxes, MENUID_SHOW_HITBOX },
7347
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Effects", onShowLayerE, MENUID_SHOW_EFFECT },
7348
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Info Opacity", onShowInfoOpacity },
7349 };
7350
7351 enum
7352 {
7353 MENUID_CHEAT_CHOP_L1,
7354 MENUID_CHEAT_CHOP_L2,
7355 MENUID_CHEAT_CHOP_L3,
7356 MENUID_CHEAT_CHOP_L4,
7357 MENUID_CHEAT_INVULN,
7358 MENUID_CHEAT_NOCLIP,
7359 MENUID_CHEAT_IGNORESV,
7360 MENUID_CHEAT_GOFAST,
7361 };
7362
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 static NewMenu cheat_menu
7363 7038 {
7364
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Set &Cheat", onCheat },
7365
1/2
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
414 { MENUID_CHEAT_CHOP_L1 },
7366
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Re&fill", &refill_menu },
7367
1/2
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
414 { MENUID_CHEAT_CHOP_L2 },
7368
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Invincible", onClock, MENUID_CHEAT_INVULN },
7369
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Ma&x Bombs...", onMaxBombs },
7370
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Heart Containers...", onHeartC },
7371
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Magic Containers...", onMagicC },
7372
1/2
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
414 { MENUID_CHEAT_CHOP_L3 },
7373
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Hero Data...", onCheatConsole },
7374
1/2
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
414 { MENUID_CHEAT_CHOP_L4 },
7375
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Walk Through &Walls", onNoWalls, MENUID_CHEAT_NOCLIP },
7376
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Hero Ignores Side&view", onIgnoreSideview, MENUID_CHEAT_IGNORESV },
7377
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Quick Movement", onGoFast, MENUID_CHEAT_GOFAST },
7378
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Kill All Enemies", onKillCheat },
7379
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Trigger &Secrets", onSecretsCheat },
7380
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Trigger Secrets Perm", onSecretsCheatPerm },
7381
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Show/Hide Layer", &show_menu },
7382
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Toggle &Light", onLightSwitch },
7383
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Goto Location...", onGoTo },
7384 };
7385
7386 #if DEVLEVEL > 0
7387 int32_t devLogging();
7388 int32_t devDebug();
7389 int32_t devTimestmp();
7390 #if DEVLEVEL > 1
7391 int32_t setCheat();
7392 #endif //DEVLEVEL > 1
7393 enum
7394 {
7395 MENUID_DEV_LOGGING,
7396 MENUID_DEV_DEBUG,
7397 MENUID_DEV_TIMESTAMP,
7398 MENUID_DEV_SETCHEAT,
7399 };
7400 static NewMenu dev_menu
7401 {
7402 { "&Force Error Log", devLogging, MENUID_DEV_LOGGING },
7403 // { "&Extra Debug Log", devDebug, MENUID_DEV_DEBUG },
7404 { "&Timestamp Log", devTimestmp, MENUID_DEV_TIMESTAMP },
7405 #if DEVLEVEL > 1
7406 {},
7407 { "Set &Cheat", setCheat, MENUID_DEV_SETCHEAT },
7408 #endif //DEVLEVEL > 1
7409 };
7410 int32_t devLogging()
7411 {
7412 dev_logging = !dev_logging;
7413 dev_menu.select_uid(MENUID_DEV_LOGGING, dev_logging);
7414 return D_O_K;
7415 }
7416 // int32_t devDebug()
7417 // {
7418 // dev_debug = !dev_debug;
7419 // dev_menu.select_uid(MENUID_DEV_DEBUG, dev_debug);
7420 // dev_menu[dv_dbg].flags = dev_debug ? D_SELECTED : 0;
7421 // return D_O_K;
7422 // }
7423 int32_t devTimestmp()
7424 {
7425 dev_timestmp = !dev_timestmp;
7426 dev_menu.select_uid(MENUID_DEV_TIMESTAMP, dev_timestmp);
7427 return D_O_K;
7428 }
7429 #if DEVLEVEL > 1
7430 int32_t setCheat()
7431 {
7432 cheat = (vbound(getnumber("Cheat Level",cheat), 0, 4));
7433 return D_O_K;
7434 }
7435 #endif //DEVLEVEL > 1
7436 #endif //DEVLEVEL > 0
7437
7438 enum
7439 {
7440 MENUID_PLAYER_CHEAT,
7441 };
7442
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 TopMenu the_player_menu
7443 2484 {
7444
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Game", &game_menu },
7445
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Settings", &settings_menu },
7446
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Cheat", &cheat_menu, MENUID_PLAYER_CHEAT, true },
7447
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Replay", &replay_menu },
7448
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&ZC", &misc_menu },
7449 #if DEVLEVEL > 0
7450 { "&Dev", &dev_menu },
7451 #endif
7452 };
7453
7454 int32_t onPauseInBackground()
7455 {
7456 if(jwin_alert3(
7457 "Toggle Pause In Background",
7458 "This action will change whether ZC Player pauses when the window loses focus.",
7459 "",
7460 "Proceed?",
7461 "&Yes",
7462 "&No",
7463 NULL,
7464 'y',
7465 'n',
7466 0,
7467 get_zc_font(font_lfont)) == 1)
7468 {
7469 pause_in_background = pause_in_background ? 0 : 1;
7470 zc_set_config("zeldadx","pause_in_background", pause_in_background);
7471 int switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7472 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7473 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7474 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7475 }
7476 options_menu.select_uid(MENUID_OPTIONS_PAUSE_BG, pause_in_background);
7477 return D_O_K;
7478 }
7479
7480 int32_t onKeyboardEntry()
7481 {
7482 NameEntryMode=0;
7483 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7484 return D_O_K;
7485 }
7486
7487 int32_t onLetterGridEntry()
7488 {
7489 NameEntryMode=1;
7490 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7491 return D_O_K;
7492 }
7493
7494 int32_t onExtLetterGridEntry()
7495 {
7496 NameEntryMode=2;
7497 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7498 return D_O_K;
7499 }
7500
7501 static BITMAP* oldscreen;
7502 int32_t onFullscreenMenu()
7503 {
7504 PALETTE oldpal;
7505 get_palette(oldpal);
7506
7507 fullscreen = !fullscreen;
7508 all_toggle_fullscreen(fullscreen);
7509 zc_set_config("zeldadx","fullscreen",fullscreen);
7510
7511 zc_set_palette(oldpal);
7512 gui_mouse_focus=0;
7513 extern int32_t switch_type;
7514 switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7515 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7516 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7517 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7518 misc_menu.select_uid(MENUID_MISC_FULLSCREEN, isFullScreen());
7519 misc_menu.select_uid(MENUID_MISC_VIDMODE, isFullScreen());
7520
7521 return D_O_K;
7522 }
7523
7524 313 void fix_menu()
7525 {
7526
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 313 times.
313 if(!debug_enabled)
7527 313 settings_menu.chop_index = 13;
7528 313 }
7529
7530 int32_t onSetSnapshotFormat(SnapshotType format)
7531 {
7532 SnapshotFormat = format;
7533 zc_set_config("zeldadx", "snapshot_format", format);
7534 snapshot_format_menu.select_only_index(format);
7535 return D_O_K;
7536 }
7537
7538 int32_t onSetBottom8Pixels(int option)
7539 {
7540 ShowBottomPixels = option;
7541 zc_set_config("zeldadx", "bottom_8_px", option);
7542 bottom_8_pixels_menu.select_only_index(option);
7543
7544 int qr = qr_HIDE_BOTTOM_8_PIXELS;
7545 bool value = false;
7546 if (option == 0)
7547 value = get_bit(quest_rules, qr) != 0; // This is the original value, as set in the qst file (or via scripting).
7548 else if (option == 1)
7549 value = false;
7550 else if (option == 2)
7551 value = true;
7552 enqueue_qr_change(qr, value);
7553
7554 return D_O_K;
7555 }
7556
7557 2917 void updateShowBottomPixels()
7558 {
7559 // It's too tricky the allow modifying the screen height between opening and closing the
7560 // active subscreen.
7561
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 2891 times.
2917 if (subscreen_open)
7562 26 return;
7563
7564
1/2
✓ Branch 0 taken 2891 times.
✗ Branch 1 not taken.
2891 if (!GameLoaded)
7565 show_bottom_8px = false;
7566 else
7567 2891 show_bottom_8px = !get_qr(qr_HIDE_BOTTOM_8_PIXELS);
7568
7569 2891 int target_bitmap_height = show_bottom_8px ? 232 : 224;
7570
2/2
✓ Branch 0 taken 2786 times.
✓ Branch 1 taken 105 times.
2891 if (framebuf->h != target_bitmap_height)
7571 {
7572 105 BITMAP* new_framebuf = create_bitmap_ex(8, 256, target_bitmap_height);
7573 105 clear_bitmap(new_framebuf);
7574 105 blit(framebuf, new_framebuf, 0, 0, 0, 0, new_framebuf->w, new_framebuf->h);
7575
7576 105 destroy_bitmap(framebuf);
7577 105 destroy_bitmap(script_menu_buf);
7578 105 destroy_bitmap(f6_menu_buf);
7579 105 destroy_bitmap(darkscr_bmp);
7580 105 destroy_bitmap(darkscr_bmp_trans);
7581
7582 105 framebuf = new_framebuf;
7583 105 script_menu_buf = create_bitmap_ex(8, 256, target_bitmap_height);
7584 105 f6_menu_buf = create_bitmap_ex(8, 256, target_bitmap_height);
7585 105 darkscr_bmp = create_bitmap_ex(8, 256, target_bitmap_height);
7586 105 darkscr_bmp_trans = create_bitmap_ex(8, 256, target_bitmap_height);
7587
7588 105 rti_game.a4_bitmap = framebuf;
7589 105 rti_game.set_size(framebuf->w, framebuf->h);
7590 105 al_set_new_bitmap_flags(ALLEGRO_CONVERT_BITMAP);
7591 105 al_destroy_bitmap(rti_game.bitmap);
7592 105 rti_game.bitmap = create_a5_bitmap(framebuf->w, framebuf->h);
7593 105 al_destroy_bitmap(rti_infolayer.bitmap);
7594 105 rti_infolayer.bitmap = create_a5_bitmap(framebuf->w, framebuf->h);
7595 105 rti_infolayer.set_size(framebuf->w, framebuf->h);
7596 105 }
7597 2917 }
7598
7599 void color_layer(RGB *src,RGB *dest,char r,char g,char b,char pos,int32_t from,int32_t to)
7600 {
7601 PALETTE tmp;
7602
7603 for(int32_t i=0; i<256; i++)
7604 {
7605 tmp[i].r=r;
7606 tmp[i].g=g;
7607 tmp[i].b=b;
7608 }
7609
7610 fade_interpolate(src,tmp,dest,pos,from,to);
7611 }
7612
7613 46 void system_pal(bool force)
7614 {
7615
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
46 if(is_sys_pal && !force) return;
7616 46 is_sys_pal = true;
7617 46 load_colorset(gui_colorset, syspal, jwin_a5_colors);
7618 46 hw_palette = &syspal;
7619 46 update_hw_pal = true;
7620 46 }
7621
7622 static uint32_t entered_sys_pal = 0;
7623 46 void enter_sys_pal()
7624 {
7625
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(is_sys_pal)
7626 {
7627 if(entered_sys_pal)
7628 ++entered_sys_pal;
7629 return;
7630 }
7631 46 sys_mouse();
7632 46 system_pal(true);
7633 46 ++entered_sys_pal;
7634 46 }
7635 46 void exit_sys_pal()
7636 {
7637
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(entered_sys_pal)
7638 {
7639
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 if(!--entered_sys_pal)
7640 {
7641 46 game_pal();
7642 46 game_mouse();
7643 46 }
7644 46 }
7645 46 }
7646
7647 void switch_out_callback()
7648 {
7649 if (pause_in_background && !MenuOpen)
7650 {
7651 System();
7652 }
7653 }
7654
7655 void switch_in_callback()
7656 {
7657 }
7658
7659 1158 void game_pal()
7660 {
7661 1158 is_sys_pal = false;
7662 1158 entered_sys_pal = 0;
7663 1158 hw_palette = &RAMpal;
7664 1158 update_hw_pal = true;
7665 1158 }
7666
7667 static char bar_str[] = "";
7668
7669 46 void music_pause()
7670 {
7671 //al_pause_duh(tmplayer);
7672 46 zcmusic_pause(zcmusic, ZCM_PAUSE);
7673
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(zcmixer->oldtrack)
7674 zcmusic_pause(zcmixer->oldtrack, ZCM_PAUSE);
7675 46 zc_midi_pause();
7676 46 }
7677
7678 void music_resume()
7679 {
7680 //al_resume_duh(tmplayer);
7681 zcmusic_pause(zcmusic, ZCM_RESUME);
7682 if (zcmixer->oldtrack)
7683 zcmusic_pause(zcmixer->oldtrack, ZCM_RESUME);
7684 zc_midi_resume();
7685 }
7686
7687 7920 void music_stop()
7688 {
7689 //al_stop_duh(tmplayer);
7690 //unload_duh(tmusic);
7691 //tmusic=NULL;
7692 //tmplayer=NULL;
7693 7920 zcmusic_stop(zcmusic);
7694 7920 zcmusic_unload_file(zcmusic);
7695
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7920 times.
7920 if (zcmixer->oldtrack)
7696 {
7697 zcmusic_stop(zcmixer->oldtrack);
7698 zcmusic_unload_file(zcmixer->oldtrack);
7699 }
7700 7920 zcmixer->newtrack = NULL;
7701 7920 zc_stop_midi();
7702 7920 currmidi=-1;
7703 7920 }
7704
7705 bool reload_fonts = false;
7706 void System()
7707 {
7708 mouse_down = gui_mouse_b();
7709 music_pause();
7710 pause_all_sfx();
7711 MenuOpen = true;
7712 enter_sys_pal();
7713 // FONT *oldfont=font;
7714 // font=tfont;
7715
7716 misc_menu.select_uid(MENUID_MISC_FULLSCREEN, isFullScreen());
7717 misc_menu.disable_uid(MENUID_MISC_VIDMODE, isFullScreen());
7718
7719 #if DEVLEVEL > 1
7720 dev_menu.disable_uid(MENUID_DEV_SETCHEAT, !Playing);
7721 #endif
7722 game_menu.disable_uid(MENUID_GAME_LOADQUEST, get_unset_save_slot());
7723 game_menu.disable_uid(MENUID_GAME_ENDGAME, !Playing);
7724 misc_menu.disable_uid(MENUID_MISC_QUEST_INFO, !Playing);
7725 misc_menu.disable_uid(MENUID_MISC_QUEST_DIR, Playing);
7726 clear_keybuf();
7727
7728 clear_bitmap(menu_bmp);
7729 oldscreen = screen;
7730 screen = menu_bmp;
7731
7732 the_player_menu.reset_state();
7733 the_player_menu.position(0, 0);
7734
7735 bool running = true;
7736 bool esc = key[KEY_ESC] || cMbtn();
7737 bool autopop = esc;
7738 do
7739 {
7740 if(reload_fonts)
7741 {
7742 init_custom_fonts();
7743 clear_bitmap(menu_bmp);
7744 broadcast_dialog_message(MSG_DRAW, 0);
7745 reload_fonts = false;
7746 }
7747 if(handle_close_btn_quit())
7748 break;
7749
7750 //update submenus
7751 {
7752 settings_menu.disable_uid(MENUID_SETTINGS_CONTROLS, replay_is_replaying());
7753 settings_menu.select_uid(MENUID_SETTINGS_CAPFPS, Throttlefps);
7754 settings_menu.select_uid(MENUID_SETTINGS_SHOWFPS, ShowFPS);
7755 settings_menu.select_uid(MENUID_SETTINGS_SHOWTIME, ShowGameTime);
7756 settings_menu.select_uid(MENUID_SETTINGS_CLICK_FREEZE, ClickToFreeze);
7757 settings_menu.select_uid(MENUID_SETTINGS_TRANSLAYERS, TransLayers);
7758 settings_menu.select_uid(MENUID_SETTINGS_NESQUIT, NESquit);
7759 settings_menu.select_uid(MENUID_SETTINGS_VOLKEYS, volkeys);
7760
7761 window_menu.select_uid(MENUID_WINDOW_LOCK_ASPECT, DragAspect);
7762 window_menu.select_uid(MENUID_WINDOW_LOCK_INTSCALE, scaleForceInteger);
7763 window_menu.select_uid(MENUID_WINDOW_SAVE_SIZE, SaveDragResize);
7764 window_menu.select_uid(MENUID_WINDOW_SAVE_POS, SaveWinPos);
7765 window_menu.select_uid(MENUID_WINDOW_STRETCH, stretchGame);
7766
7767 options_menu.select_uid(MENUID_OPTIONS_EPILEPSYPROT, epilepsyFlashReduction);
7768 options_menu.select_uid(MENUID_OPTIONS_PAUSE_BG, pause_in_background);
7769 options_menu.disable_uid(MENUID_OPTIONS_SHOWBOTTOMPIXELS, replay_is_replaying());
7770
7771 name_entry_mode_menu.select_only_index(NameEntryMode);
7772
7773 misc_menu.select_uid(MENUID_MISC_CONSOLE, console_enabled);
7774 misc_menu.select_uid(MENUID_MISC_CLEAR_CONSOLE_ON_LOAD, clearConsoleOnLoad);
7775
7776 bool nocheat = (replay_is_replaying() || !Playing
7777 || (!maxcheat && !zcheats.flags && !get_debug() && DEVLEVEL < 2 && !zqtesting_mode && !devpwd()));
7778 the_player_menu.disable_uid(MENUID_PLAYER_CHEAT, nocheat);
7779 refill_menu.disable_uid(MENUID_REFILL_ARROWS, !get_qr(qr_TRUEARROWS));
7780 cheat_menu.chop_index.reset();
7781 if(cheat < 4)
7782 cheat_menu.chop_index = cheat_menu.ind_at(MENUID_CHEAT_CHOP_L1+cheat);
7783 cheat_menu.select_uid(MENUID_CHEAT_INVULN, getClock());
7784 cheat_menu.select_uid(MENUID_CHEAT_NOCLIP, toogam);
7785 cheat_menu.select_uid(MENUID_CHEAT_IGNORESV, ignoreSideview);
7786 cheat_menu.select_uid(MENUID_CHEAT_GOFAST, gofast);
7787
7788 show_menu.select_uid(MENUID_SHOW_L0, show_layers[0]);
7789 show_menu.select_uid(MENUID_SHOW_L1, show_layers[1]);
7790 show_menu.select_uid(MENUID_SHOW_L2, show_layers[2]);
7791 show_menu.select_uid(MENUID_SHOW_L3, show_layers[3]);
7792 show_menu.select_uid(MENUID_SHOW_L4, show_layers[4]);
7793 show_menu.select_uid(MENUID_SHOW_L5, show_layers[5]);
7794 show_menu.select_uid(MENUID_SHOW_L6, show_layers[6]);
7795 show_menu.select_uid(MENUID_SHOW_OVER, show_layer_over);
7796 show_menu.select_uid(MENUID_SHOW_PUSH, show_layer_push);
7797 show_menu.select_uid(MENUID_SHOW_SPR, show_sprites);
7798 show_menu.select_uid(MENUID_SHOW_FFC, show_ffcs);
7799 show_menu.select_uid(MENUID_SHOW_SOLIDITY, show_walkflags);
7800 show_menu.select_uid(MENUID_SHOW_SCRIPTNAME, show_ff_scripts);
7801 show_menu.select_uid(MENUID_SHOW_HITBOX, show_hitboxes);
7802 show_menu.select_uid(MENUID_SHOW_EFFECT, show_effectflags);
7803
7804 settings_menu.select_uid(MENUID_SETTINGS_HEARTBEEP, heart_beep);
7805 settings_menu.select_uid(MENUID_SETTINGS_SAVEINDICATOR, use_save_indicator);
7806
7807 replay_menu.by_uid(MENUID_REPLAY_STOP)->text = fmt::format("Stop {}",
7808 replay_get_mode() == ReplayMode::Record ? "recording" : "replaying");
7809
7810 replay_menu.select_uid(MENUID_REPLAY_RECORDNEW, zc_get_config("zeldadx", "replay_new_saves", false));
7811 #ifdef HAS_CURL
7812 replay_menu.select_uid(MENUID_REPLAY_AUTOUPLOAD, replay_upload_auto_enabled());
7813 #endif
7814 replay_menu.disable_uid(MENUID_REPLAY_STOP, !replay_is_active());
7815 replay_menu.disable_uid(MENUID_REPLAY_SAVE, replay_get_mode() != ReplayMode::Record);
7816 replay_menu.select_uid(MENUID_REPLAY_SNAP_ALL, replay_is_snapshot_all_frames());
7817
7818 snapshot_format_menu.select_only_index(SnapshotFormat);
7819 bottom_8_pixels_menu.select_only_index(ShowBottomPixels);
7820 }
7821
7822 if(debug_enabled)
7823 settings_menu.select_uid(MENUID_SETTINGS_DEBUG, get_debug());
7824
7825 if(autopop)
7826 clear_keybuf();
7827 the_player_menu.run(true);
7828 if(autopop)
7829 {
7830 the_player_menu.pop_sub(0, &the_player_menu);
7831 the_player_menu.draw(screen, the_player_menu.hovered_ind());
7832 autopop = false;
7833 update_hw_screen();
7834 }
7835
7836 update_hw_screen();
7837
7838 auto mb = gui_mouse_b();
7839 if(XOR(mb, mouse_down))
7840 {
7841 if(!the_player_menu.has_mouse())
7842 if(mb)
7843 break;
7844 mouse_down = mb;
7845 }
7846
7847 if(input_idle(true) > after_time())
7848 // run Screeen Saver
7849 {
7850 // Screen saver enabled for now.
7851 clear_keybuf();
7852 Matrix(ss_speed, ss_density, 0);
7853 system_pal(true);
7854 sys_mouse();
7855 }
7856
7857 poll_keyboard();
7858 if(esc)
7859 {
7860 if(!key[KEY_ESC])
7861 esc = false;
7862 }
7863
7864 if(keypressed() && !CHECK_ALT) //System hotkeys
7865 {
7866 auto c = peekkey();
7867 bool eatkey = true;
7868 switch(c>>8)
7869 {
7870 //Spare keys used by the menu
7871 case KEY_UP:
7872 case KEY_DOWN:
7873 case KEY_LEFT:
7874 case KEY_RIGHT:
7875 eatkey = false;
7876 break;
7877 case KEY_F1:
7878 onThrottleFPS();
7879 break;
7880 case KEY_F2:
7881 onShowFPS();
7882 break;
7883 case KEY_F6:
7884 onTryQuitMenu();
7885 break;
7886 #ifndef ALLEGRO_MACOSX
7887 case KEY_F9:
7888 onReset();
7889 break;
7890 case KEY_F10:
7891 onExit();
7892 break;
7893 #else
7894 case KEY_F7:
7895 onReset();
7896 break;
7897 case KEY_F8:
7898 onExit();
7899 break;
7900 #endif
7901 case KEY_F12:
7902 onSnapshot();
7903 break;
7904 case KEY_TAB:
7905 onDebug();
7906 break;
7907 case KEY_ESC:
7908 if(!esc)
7909 running = false;
7910 break;
7911 }
7912 if(eatkey)
7913 readkey();
7914 }
7915 if(Quit || (GameFlags & GAMEFLAG_TRYQUIT))
7916 break;
7917 }
7918 while(running);
7919
7920 screen = oldscreen;
7921
7922 mouse_down=gui_mouse_b();
7923 MenuOpen = false;
7924 if(Quit)
7925 {
7926 kill_sfx();
7927 music_stop();
7928 update_hw_screen();
7929 }
7930 else
7931 {
7932 music_resume();
7933 resume_all_sfx();
7934
7935 if(rc)
7936 ringcolor(false);
7937 }
7938 exit_sys_pal();
7939
7940 eat_buttons();
7941
7942 rc=false;
7943 clear_keybuf();
7944
7945 zc_init_apply_cheat_delta();
7946 }
7947
7948 313 void fix_dialogs()
7949 {
7950 313 jwin_center_dialog(about_dlg);
7951 313 jwin_center_dialog(gamepad_dlg);
7952 313 jwin_center_dialog(credits_dlg);
7953 313 jwin_center_dialog(gamemode_dlg);
7954 313 jwin_center_dialog(getnum_dlg);
7955 313 jwin_center_dialog(goto_dlg);
7956 313 jwin_center_dialog(keyboard_control_dlg);
7957 313 jwin_center_dialog(midi_dlg);
7958 313 jwin_center_dialog(quest_dlg);
7959 313 jwin_center_dialog(scrsaver_dlg);
7960 313 jwin_center_dialog(sound_dlg);
7961 313 jwin_center_dialog(triforce_dlg);
7962 313 }
7963
7964 4329 INLINE int32_t mixvol(int32_t v1,int32_t v2)
7965 {
7966
3/4
✓ Branch 0 taken 4329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4307 times.
✓ Branch 3 taken 22 times.
4329 return (zc_min(v1,255)*zc_min(v2,255)) >> 8;
7967 }
7968
7969 292 int32_t get_emusic_volume()
7970 {
7971 292 int32_t temp_volume = emusic_volume;
7972
2/4
✓ Branch 0 taken 292 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 292 times.
✗ Branch 3 not taken.
292 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
7973 temp_volume = (emusic_volume * FFCore.usr_music_volume) / 10000 / 100;
7974
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 292 times.
292 if (!zcmusic)
7975 292 return temp_volume;
7976 return (temp_volume * zcmusic->fadevolume) / 10000;
7977 292 }
7978
7979 int32_t get_zcmusicpos()
7980 {
7981 int32_t debugtracething = zcmusic_get_curpos(zcmusic);
7982 return debugtracething;
7983 return 0;
7984 }
7985
7986 void set_zcmusicpos(int32_t position)
7987 {
7988 zcmusic_set_curpos(zcmusic, position);
7989 }
7990
7991 void set_zcmusicspeed(int32_t speed)
7992 {
7993 zcmusic_set_speed(zcmusic, speed);
7994 }
7995
7996 int32_t get_zcmusiclen()
7997 {
7998 return zcmusic_get_length(zcmusic);
7999 }
8000
8001 3 void set_zcmusicloop(double start, double end)
8002 {
8003 3 zcmusic_set_loop(zcmusic, start, end);
8004 3 }
8005
8006 64164 void jukebox(int32_t index,int32_t loop)
8007 {
8008
1/2
✓ Branch 0 taken 64164 times.
✗ Branch 1 not taken.
64164 if (is_headless())
8009 64164 return;
8010
8011 music_stop();
8012
8013 if(index<0) index=MAXMIDIS-1;
8014
8015 if(index>=MAXMIDIS) index=0;
8016
8017 music_stop();
8018
8019 // Allegro's DIGMID driver (the one normally used on on Linux) gets
8020 // stuck notes when a song stops. This fixes it.
8021 if(strcmp(midi_driver->name, "DIGMID")==0)
8022 zc_set_volume(0, 0);
8023
8024 zc_set_volume(-1, mixvol(tunes[index].volume, midi_volume >>1));
8025 zc_play_midi(tunes[index].data,loop);
8026
8027 if(tunes[index].start>0)
8028 zc_midi_seek(tunes[index].start);
8029
8030 midi_loop_start = tunes[index].loop_start;
8031 midi_loop_end = tunes[index].loop_end;
8032
8033 currmidi=index;
8034 master_volume(digi_volume, midi_volume);
8035 //midi_paused=false;
8036 64164 }
8037
8038 64164 void jukebox(int32_t index)
8039 {
8040
1/2
✓ Branch 0 taken 64164 times.
✗ Branch 1 not taken.
64164 if(index<0) index=MAXMIDIS-1;
8041
8042
1/2
✓ Branch 0 taken 64164 times.
✗ Branch 1 not taken.
64164 if(index>=MAXMIDIS) index=0;
8043
8044 // do nothing if it's already playing
8045
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 64164 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
64164 if(index==currmidi && midi_pos>=0)
8046 {
8047 return;
8048 }
8049
8050 64164 jukebox(index,tunes[index].loop);
8051 64164 }
8052
8053 102 void play_DmapMusic()
8054 {
8055
1/2
✓ Branch 0 taken 102 times.
✗ Branch 1 not taken.
102 if (is_headless())
8056 102 return;
8057
8058 static char tfile[2048];
8059 static int32_t ttrack=0;
8060 bool domidi=false;
8061
8062 int32_t fadeoutframes = 0;
8063 if (zcmusic != NULL)
8064 fadeoutframes = zcmusic->fadeoutframes;
8065
8066 if(DMaps[cur_dmap].tmusic[0]!=0)
8067 {
8068 if(zcmusic==NULL ||
8069 strcmp(zcmusic->filename,DMaps[cur_dmap].tmusic)!=0 ||
8070 (zcmusic->type==ZCMF_GME && zcmusic->track != DMaps[cur_dmap].tmusictrack))
8071 {
8072 if (DMaps[cur_dmap].tmusic_xfade_in > 0 || fadeoutframes > 0)
8073 {
8074 if (play_enh_music_crossfade(DMaps[cur_dmap].tmusic, qstpath, DMaps[cur_dmap].tmusictrack, get_emusic_volume(), DMaps[cur_dmap].tmusic_xfade_in, fadeoutframes))
8075 {
8076 if (zcmusic != NULL)
8077 {
8078 zcmusic->fadeoutframes = DMaps[cur_dmap].tmusic_xfade_out;
8079 zcmusic_set_loop(zcmusic, double(DMaps[cur_dmap].tmusic_loop_start / 10000.0), double(DMaps[cur_dmap].tmusic_loop_end / 10000.0));
8080 }
8081 }
8082 }
8083 else
8084 {
8085 if (zcmusic != NULL)
8086 {
8087 zcmusic_stop(zcmusic);
8088 zcmusic_unload_file(zcmusic);
8089 zcmusic = NULL;
8090 zcmixer->newtrack = NULL;
8091 }
8092
8093 zcmusic = zcmusic_load_for_quest(DMaps[cur_dmap].tmusic, qstpath).first;
8094 zcmixer->newtrack = zcmusic;
8095
8096 if (zcmusic != NULL)
8097 {
8098 zc_stop_midi();
8099 strcpy(tfile, DMaps[cur_dmap].tmusic);
8100 zcmusic_play(zcmusic, emusic_volume);
8101 int32_t temptracks = 0;
8102 temptracks = zcmusic_get_tracks(zcmusic);
8103 temptracks = (temptracks < 2) ? 1 : temptracks;
8104 ttrack = vbound(DMaps[cur_dmap].tmusictrack, 0, temptracks - 1);
8105 zcmusic_change_track(zcmusic, ttrack);
8106 zcmusic_set_loop(zcmusic, double(DMaps[cur_dmap].tmusic_loop_start / 10000.0), double(DMaps[cur_dmap].tmusic_loop_end / 10000.0));
8107 }
8108 else
8109 {
8110 tfile[0] = 0;
8111 domidi = true;
8112 }
8113 }
8114 }
8115 }
8116 else
8117 {
8118 if (DMaps[cur_dmap].midi == 0 && fadeoutframes > 0 && zcmusic != NULL && strcmp(zcmusic->filename, DMaps[cur_dmap].tmusic) != 0)
8119 {
8120 play_enh_music_crossfade(NULL, qstpath, DMaps[cur_dmap].tmusictrack, get_emusic_volume(), DMaps[cur_dmap].tmusic_xfade_in, fadeoutframes);
8121 }
8122 else
8123 {
8124 domidi = true;
8125 }
8126 }
8127
8128 if(domidi)
8129 {
8130 int32_t m=DMaps[cur_dmap].midi;
8131
8132 switch(m)
8133 {
8134 case 1:
8135 jukebox(ZC_MIDI_OVERWORLD);
8136 break;
8137
8138 case 2:
8139 jukebox(ZC_MIDI_DUNGEON);
8140 break;
8141
8142 case 3:
8143 jukebox(ZC_MIDI_LEVEL9);
8144 break;
8145
8146 default:
8147 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8148 jukebox(m+MIDIOFFSET_DMAP);
8149 else
8150 music_stop();
8151 }
8152 }
8153 102 }
8154
8155 35714 void playLevelMusic()
8156 {
8157
1/2
✓ Branch 0 taken 35714 times.
✗ Branch 1 not taken.
35714 if (is_headless())
8158 35714 return;
8159
8160 int32_t m=hero_scr->screen_midi;
8161
8162 switch(m)
8163 {
8164 case -2:
8165 music_stop();
8166 break;
8167
8168 case -1:
8169 play_DmapMusic();
8170 break;
8171
8172 case 1:
8173 jukebox(ZC_MIDI_OVERWORLD);
8174 break;
8175
8176 case 2:
8177 jukebox(ZC_MIDI_DUNGEON);
8178 break;
8179
8180 case 3:
8181 jukebox(ZC_MIDI_LEVEL9);
8182 break;
8183
8184 default:
8185 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8186 jukebox(m+MIDIOFFSET_MAPSCR);
8187 else
8188 music_stop();
8189 }
8190 35714 }
8191
8192 4329 void master_volume(int32_t dv,int32_t mv)
8193 {
8194
7/8
✓ Branch 0 taken 2008 times.
✓ Branch 1 taken 2321 times.
✓ Branch 2 taken 1967 times.
✓ Branch 3 taken 354 times.
✓ Branch 4 taken 2321 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1967 times.
✓ Branch 7 taken 354 times.
4329 if(dv>=0) digi_volume=zc_max(zc_min(dv,255),0);
8195
8196
7/8
✓ Branch 0 taken 2004 times.
✓ Branch 1 taken 2325 times.
✓ Branch 2 taken 2000 times.
✓ Branch 3 taken 325 times.
✓ Branch 4 taken 2325 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2000 times.
✓ Branch 7 taken 325 times.
4329 if(mv>=0) midi_volume=zc_max(zc_min(mv,255),0);
8197
8198
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 4329 times.
✓ Branch 2 taken 4329 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4329 times.
4329 int32_t i = zc_min(zc_max(currmidi,0),MAXMIDIS-1);
8199 4329 int32_t temp_vol = midi_volume;
8200
2/2
✓ Branch 0 taken 4016 times.
✓ Branch 1 taken 313 times.
4329 if (!get_qr(qr_OLD_SCRIPT_VOLUME))
8201 313 temp_vol = (midi_volume * FFCore.usr_music_volume) / 10000 / 100;
8202 4329 zc_set_volume(digi_volume,mixvol(tunes[i].volume, temp_vol));
8203 4329 }
8204
8205 // array of voices, one for each sfx sample in the data file
8206 // 0+ = voice #
8207 // -1 = voice not allocated
8208 313 void Z_init_sound()
8209 {
8210
2/2
✓ Branch 0 taken 80128 times.
✓ Branch 1 taken 313 times.
80441 for(int32_t i=0; i<WAV_COUNT; i++)
8211 80128 sfx_voice[i]=-1;
8212
8213 313 const char* midis[ZC_MIDI_COUNT] = {
8214 "assets/dungeon.mid",
8215 "assets/ending.mid",
8216 "assets/gameover.mid",
8217 "assets/level9.mid",
8218 "assets/overworld.mid",
8219 "assets/title.mid",
8220 "assets/triforce.mid",
8221 };
8222
2/2
✓ Branch 0 taken 2191 times.
✓ Branch 1 taken 313 times.
2504 for(int32_t i=0; i<ZC_MIDI_COUNT; i++)
8223 {
8224 2191 tunes[i].data = load_midi(midis[i]);
8225
1/2
✓ Branch 0 taken 2191 times.
✗ Branch 1 not taken.
2191 if (!tunes[i].data)
8226 Z_error_fatal("Missing required file %s\n", midis[i]);
8227 2191 }
8228
8229
2/2
✓ Branch 0 taken 78876 times.
✓ Branch 1 taken 313 times.
79189 for(int32_t j=0; j<MAXCUSTOMMIDIS; j++)
8230 78876 tunes[ZC_MIDI_COUNT+j].data=NULL;
8231
8232 313 master_volume(digi_volume,midi_volume);
8233 313 }
8234
8235 // returns number of voices currently allocated
8236 int32_t sfx_count()
8237 {
8238 int32_t c=0;
8239
8240 for(int32_t i=0; i<WAV_COUNT; i++)
8241 if(sfx_voice[i]!=-1)
8242 ++c;
8243
8244 return c;
8245 }
8246
8247 // clean up finished samples
8248 18311193 void sfx_cleanup()
8249 {
8250
2/2
✓ Branch 0 taken 4687665408 times.
✓ Branch 1 taken 18311193 times.
4705976601 for(int32_t i=0; i<WAV_COUNT; i++)
8251
3/4
✓ Branch 0 taken 1267262 times.
✓ Branch 1 taken 4686398146 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1267262 times.
4688932670 if(sfx_voice[i]!=-1 && voice_get_position(sfx_voice[i])<0)
8252 {
8253 1267262 deallocate_voice(sfx_voice[i]);
8254 1267262 sfx_voice[i]=-1;
8255 1267262 }
8256 18311193 }
8257
8258 1267427 SAMPLE* sfx_get_sample(int32_t index)
8259 {
8260 // check index
8261
2/4
✓ Branch 0 taken 1267427 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1267427 times.
1267427 if (index<=0 || index>=WAV_COUNT)
8262 return nullptr;
8263
8264
2/2
✓ Branch 0 taken 446247 times.
✓ Branch 1 taken 821180 times.
1267427 if (sfxdat)
8265 {
8266
1/2
✓ Branch 0 taken 446247 times.
✗ Branch 1 not taken.
446247 if (index<Z35)
8267 {
8268 446247 return (SAMPLE*)sfxdata[index].dat;
8269 }
8270 else
8271 {
8272 return (SAMPLE*)sfxdata[Z35].dat;
8273 }
8274 }
8275 else
8276 {
8277 821180 return &customsfxdata[index];
8278 }
8279
8280 return nullptr;
8281 1267427 }
8282
8283 // allocates a voice for the sample "wav_index" (index into zelda.dat)
8284 // if a voice is already allocated (and/or playing), then it just returns true
8285 // Returns true: voice is allocated
8286 // false: unsuccessful
8287 1880839 bool sfx_init(int32_t index)
8288 {
8289 // check index
8290
3/4
✓ Branch 0 taken 1400147 times.
✓ Branch 1 taken 480692 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1400147 times.
1880839 if(index<=0 || index>=WAV_COUNT)
8291 480692 return false;
8292
8293
2/2
✓ Branch 0 taken 132780 times.
✓ Branch 1 taken 1267367 times.
1400147 if (sfx_voice[index] == -1)
8294 {
8295 1267367 SAMPLE* sample = sfx_get_sample(index);
8296
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1267367 times.
1267367 if (!sample)
8297 return false;
8298
8299 1267367 sfx_voice[index] = allocate_voice(sample);
8300 1267367 }
8301
8302 1400147 return sfx_voice[index] != -1;
8303 1880839 }
8304
8305 int32_t sfx_get_default_freq(int32_t index)
8306 {
8307 if (sfxdat)
8308 {
8309 if (index < Z35)
8310 {
8311 return ((SAMPLE*)sfxdata[index].dat)->freq;
8312 }
8313 else
8314 {
8315 return ((SAMPLE*)sfxdata[Z35].dat)->freq;
8316 }
8317 }
8318 else
8319 {
8320 return customsfxdata[index].freq;
8321 }
8322 }
8323
8324 int32_t sfx_get_length(int32_t index)
8325 {
8326 if (sfxdat)
8327 {
8328 if (index < Z35)
8329 {
8330 return int32_t(((SAMPLE*)sfxdata[index].dat)->len);
8331 }
8332 else
8333 {
8334 return int32_t(((SAMPLE*)sfxdata[Z35].dat)->len);
8335 }
8336 }
8337 else
8338 {
8339 return int32_t(customsfxdata[index].len);
8340 }
8341 }
8342
8343 // plays an sfx sample
8344 1880839 void sfx(int32_t index,int32_t pan,bool loop, bool restart, int32_t vol, int32_t freq)
8345 {
8346
2/2
✓ Branch 0 taken 1400147 times.
✓ Branch 1 taken 480692 times.
1880839 if(!sfx_init(index))
8347 480692 return;
8348
1/2
✓ Branch 0 taken 1400147 times.
✗ Branch 1 not taken.
1400147 if (!is_headless())
8349 {
8350 voice_set_playmode(sfx_voice[index], loop ? PLAYMODE_LOOP : PLAYMODE_PLAY);
8351 voice_set_pan(sfx_voice[index], pan);
8352
8353 // Only used by ZScript currently
8354 if (freq <= -1)
8355 {
8356 freq = sfx_get_default_freq(index);
8357 }
8358 voice_set_frequency(sfx_voice[index], freq);
8359
8360 // Only used by ZScript currently
8361 int32_t temp_volume = (sfx_volume * vol) / 10000 / 100;
8362 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
8363 temp_volume = (temp_volume * FFCore.usr_sfx_volume) / 10000 / 100;
8364 voice_set_volume(sfx_voice[index], temp_volume);
8365
8366 int32_t pos = voice_get_position(sfx_voice[index]);
8367
8368 if (restart) voice_set_position(sfx_voice[index], 0);
8369
8370 if (pos <= 0)
8371 voice_start(sfx_voice[index]);
8372 }
8373
8374
3/4
✓ Branch 0 taken 865732 times.
✓ Branch 1 taken 534415 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 865732 times.
1400147 if (restart && replay_is_debug())
8375 {
8376 // TODO(replays): get rid of this bandaid next time replays are mass-updated.
8377 865732 const char* sfx_name = sfx_string[index];
8378
2/2
✓ Branch 0 taken 853932 times.
✓ Branch 1 taken 11800 times.
865732 if (strcmp(sfx_name, "Hero is hit") == 0)
8379 11800 sfx_name = "Player is hit";
8380
2/2
✓ Branch 0 taken 853805 times.
✓ Branch 1 taken 127 times.
853932 else if (strcmp(sfx_name, "Hero dies") == 0)
8381 127 sfx_name = "Player dies";
8382
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 865732 times.
865732 replay_step_comment(fmt::format("sfx {}", sfx_name));
8383 865732 }
8384 1880839 }
8385
8386 // true if sfx is allocated
8387 203255 bool sfx_allocated(int32_t index)
8388 {
8389
3/4
✓ Branch 0 taken 33546 times.
✓ Branch 1 taken 169709 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 33546 times.
203255 return (index>0 && index<WAV_COUNT && sfx_voice[index]!=-1);
8390 }
8391
8392 // start it (in loop mode) if it's not already playing,
8393 // otherwise adjust it to play in loop mode -DD
8394 118478 void cont_sfx(int32_t index)
8395 {
8396
1/2
✓ Branch 0 taken 118478 times.
✗ Branch 1 not taken.
118478 if (is_headless())
8397 118478 return;
8398
8399 if(!sfx_init(index))
8400 {
8401 return;
8402 }
8403
8404 if(voice_get_position(sfx_voice[index])<=0)
8405 {
8406 voice_set_position(sfx_voice[index],0);
8407 voice_set_playmode(sfx_voice[index],PLAYMODE_LOOP);
8408 voice_set_volume(sfx_voice[index], sfx_volume);
8409 voice_start(sfx_voice[index]);
8410 }
8411 else
8412 {
8413 adjust_sfx(index, 128, true);
8414 }
8415 118478 }
8416
8417 // adjust parameters while playing
8418 4948 void adjust_sfx(int32_t index,int32_t pan,bool loop)
8419 {
8420
4/6
✓ Branch 0 taken 4511 times.
✓ Branch 1 taken 437 times.
✓ Branch 2 taken 4511 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4511 times.
4948 if(index<=0 || index>=WAV_COUNT || sfx_voice[index]==-1)
8421 4948 return;
8422
8423 voice_set_playmode(sfx_voice[index],loop?PLAYMODE_LOOP:PLAYMODE_PLAY);
8424 voice_set_pan(sfx_voice[index],pan);
8425 4948 }
8426
8427 // pauses a voice
8428 3254 void pause_sfx(int32_t index)
8429 {
8430
3/6
✓ Branch 0 taken 3254 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3254 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3254 times.
3254 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8431 voice_stop(sfx_voice[index]);
8432 3254 }
8433
8434 // resumes a voice
8435 1372 void resume_sfx(int32_t index)
8436 {
8437
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1372 times.
1372 if (is_headless())
8438 1372 return;
8439
8440 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8441 voice_start(sfx_voice[index]);
8442 1372 }
8443
8444 // pauses all active voices
8445 1063 void pause_all_sfx()
8446 {
8447
2/2
✓ Branch 0 taken 272128 times.
✓ Branch 1 taken 1063 times.
273191 for(int32_t i=0; i<WAV_COUNT; i++)
8448
2/2
✓ Branch 0 taken 272126 times.
✓ Branch 1 taken 2 times.
272130 if(sfx_voice[i]!=-1)
8449 2 voice_stop(sfx_voice[i]);
8450 1063 }
8451
8452 // resumes all paused voices
8453 1017 void resume_all_sfx()
8454 {
8455
2/2
✓ Branch 0 taken 260352 times.
✓ Branch 1 taken 1017 times.
261369 for(int32_t i=0; i<WAV_COUNT; i++)
8456
1/2
✓ Branch 0 taken 260352 times.
✗ Branch 1 not taken.
260352 if(sfx_voice[i]!=-1)
8457 voice_start(sfx_voice[i]);
8458 1017 }
8459
8460 // stops an sfx and deallocates the voice
8461 14618908 void stop_sfx(int32_t index)
8462 {
8463
3/4
✓ Branch 0 taken 14371862 times.
✓ Branch 1 taken 247046 times.
✓ Branch 2 taken 14371862 times.
✗ Branch 3 not taken.
14618908 if(index<=0 || index>=WAV_COUNT)
8464 247046 return;
8465
8466
2/2
✓ Branch 0 taken 47 times.
✓ Branch 1 taken 14371815 times.
14371862 if(sfx_voice[index]!=-1)
8467 {
8468 47 deallocate_voice(sfx_voice[index]);
8469 47 sfx_voice[index]=-1;
8470 47 }
8471 14618908 }
8472
8473 // Stops SFX played by Hero's item of the given family
8474 163371 void stop_item_sfx(int32_t family)
8475 {
8476 163371 int32_t id=current_item_id(family);
8477
8478
2/2
✓ Branch 0 taken 162269 times.
✓ Branch 1 taken 1102 times.
163371 if(id<0)
8479 162269 return;
8480
8481 1102 stop_sfx(itemsbuf[id].usesound);
8482 163371 }
8483
8484 9357 void kill_sfx()
8485 {
8486
2/2
✓ Branch 0 taken 2395392 times.
✓ Branch 1 taken 9357 times.
2404749 for(int32_t i=0; i<WAV_COUNT; i++)
8487
2/2
✓ Branch 0 taken 2395334 times.
✓ Branch 1 taken 58 times.
2395450 if(sfx_voice[i]!=-1)
8488 {
8489 58 deallocate_voice(sfx_voice[i]);
8490 58 sfx_voice[i]=-1;
8491 58 }
8492 9357 }
8493
8494 // TODO: when far out of bounds, sounds should dampen. currently we only pan.
8495 1191379 int32_t pan(int32_t x)
8496 {
8497
1/5
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1191379 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1191379 switch(pan_style)
8498 {
8499 // MONO
8500 case 0:
8501 return 128;
8502
8503 // 1/2
8504 case 1:
8505 1191379 x -= viewport.x;
8506 1191379 return vbound((x>>1)+68,0,255);
8507
8508 // 3/4
8509 case 2:
8510 x -= viewport.x;
8511 return vbound(((x*3)>>2)+36,0,255);
8512
8513 // FULL
8514 case 3:
8515 default:
8516 x -= viewport.x;
8517 return vbound(x,0,255);
8518 }
8519 1191379 }
8520
8521 50408176 bool joybtn(int32_t b)
8522 {
8523
1/2
✓ Branch 0 taken 50408176 times.
✗ Branch 1 not taken.
50408176 if(b == 0)
8524 return false;
8525
1/2
✓ Branch 0 taken 50408176 times.
✗ Branch 1 not taken.
50408176 if (b-1 >= joy[joystick_index].num_buttons)
8526 50408176 return false;
8527
8528 return joy[joystick_index].button[b-1].b !=0;
8529 50408176 }
8530
8531 bool joystick(int32_t s)
8532 {
8533 if(s < 0)
8534 return false;
8535 if (s >= joy[joystick_index].num_sticks)
8536 return false;
8537
8538 for (int i = 0; i < joy[joystick_index].stick[s].num_axis; i++)
8539 {
8540 if (joy[joystick_index].stick[s].axis[i].d1 || joy[joystick_index].stick[s].axis[i].d2)
8541 return true;
8542 }
8543 return false;
8544 }
8545
8546 const char* joybtn_name(int32_t b)
8547 {
8548 if (b <= 0 || b > joy[joystick_index].num_buttons)
8549 return "";
8550
8551 return joy[joystick_index].button[b-1].name;
8552 }
8553
8554 const char* joystick_name(int32_t s)
8555 {
8556 if (s < 0 || s >= joy[joystick_index].num_sticks)
8557 return "";
8558
8559 return joy[joystick_index].stick[s].name;
8560 }
8561
8562 int32_t button_pressed()
8563 {
8564 if (joystick_index >= MAX_JOYSTICKS)
8565 return 0;
8566
8567 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8568 {
8569 if(joybtn(i))
8570 return i;
8571 }
8572
8573 return 0;
8574 }
8575
8576 int32_t next_press_key();
8577
8578 int32_t next_joy_input(bool buttons)
8579 {
8580 clear_keybuf();
8581
8582 //first, we need to wait until they're pressing no buttons
8583 for(;;)
8584 {
8585 if(keypressed())
8586 {
8587 switch(readkey()>>8)
8588 {
8589 case KEY_ESC:
8590 return -1;
8591
8592 case KEY_SPACE:
8593 return 0;
8594 }
8595 }
8596
8597 poll_joystick();
8598 bool done = true;
8599
8600 if (buttons)
8601 {
8602 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8603 {
8604 if(joybtn(i)) done = false;
8605 }
8606 }
8607 else
8608 {
8609 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8610 {
8611 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8612 return -2;
8613 }
8614 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8615 {
8616 if(joystick(i)) done = false;
8617 }
8618 }
8619
8620 if(done) break;
8621 rest(1);
8622 }
8623
8624 //now, we need to wait for them to press any button
8625 for(;;)
8626 {
8627 if(keypressed())
8628 {
8629 switch(readkey()>>8)
8630 {
8631 case KEY_ESC:
8632 return -1;
8633
8634 case KEY_SPACE:
8635 return 0;
8636 }
8637 }
8638
8639 poll_joystick();
8640
8641 if (buttons)
8642 {
8643 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8644 {
8645 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8646 return -2;
8647 }
8648 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8649 {
8650 if(joybtn(i))
8651 return i;
8652 }
8653 }
8654 else
8655 {
8656 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8657 {
8658 if(joystick(i))
8659 return i;
8660 }
8661 }
8662 rest(1);
8663 }
8664 }
8665
8666 7853012 static bool rButton(bool &btn, bool &flag, bool rawbtn)
8667 {
8668
2/2
✓ Branch 0 taken 7824635 times.
✓ Branch 1 taken 28377 times.
7853012 bool ret = btn && !flag;
8669 7853012 flag = rawbtn;
8670
8671 7853012 return ret;
8672 }
8673 376913088 static bool rButton(bool &btn, bool &flag)
8674 {
8675
2/2
✓ Branch 0 taken 362997090 times.
✓ Branch 1 taken 13915998 times.
376913088 bool ret = btn && !flag;
8676 376913088 flag = btn;
8677
8678 376913088 return ret;
8679 }
8680 4643423 static bool rButtonPeek(bool btn, bool flag)
8681 {
8682
2/2
✓ Branch 0 taken 4296162 times.
✓ Branch 1 taken 347261 times.
4643423 if(!btn)
8683 {
8684 4296162 return false;
8685 }
8686
2/2
✓ Branch 0 taken 33613 times.
✓ Branch 1 taken 313648 times.
347261 else if(!flag)
8687 {
8688 33613 return true;
8689 }
8690
8691 313648 return false;
8692 4643423 }
8693
8694 // Updated only by keyboard/gamepad.
8695 // If in replay mode, this is set directly by the replay system.
8696 // This should never be read from directly - use control_state instead.
8697 bool raw_control_state[ZC_CONTROL_STATES];
8698
8699 // Every call to load_control_state (pretty much every frame) resets this to be equal to raw_control_state.
8700 // This state can drift from raw_control_state if button states are "eaten" or overriden by a script. But that only
8701 // lasts until the next call to load_control_state.
8702 bool control_state[ZC_CONTROL_STATES];
8703 bool disable_control[ZC_CONTROL_STATES];
8704 bool drunk_toggle_state[11];
8705 bool disabledKeys[127];
8706 bool KeyInput[127];
8707 bool KeyPress[127];
8708
8709 bool key_current_frame[127];
8710 bool key_previous_frame[127];
8711
8712 static bool key_system[127];
8713 static bool key_system_previous[127];
8714 static bool key_system_press[127];
8715
8716 bool button_press[ZC_CONTROL_STATES];
8717 bool button_hold[ZC_CONTROL_STATES];
8718
8719 #define STICK_1_X joy[joystick_index].stick[js_stick_1_x_stick].axis[js_stick_1_x_axis]
8720 #define STICK_1_Y joy[joystick_index].stick[js_stick_1_y_stick].axis[js_stick_1_y_axis]
8721 #define STICK_2_X joy[joystick_index].stick[js_stick_2_x_stick].axis[js_stick_2_x_axis]
8722 #define STICK_2_Y joy[joystick_index].stick[js_stick_2_y_stick].axis[js_stick_2_y_axis]
8723 #define STICK_PRECISION 56 //define your own sensitivity
8724
8725 15664553 void load_control_state()
8726 {
8727 15664553 load_control_called_this_frame = true;
8728
8729
2/2
✓ Branch 0 taken 12461491 times.
✓ Branch 1 taken 3203062 times.
15664553 if (replay_version_check(8, 11))
8730 {
8731
2/2
✓ Branch 0 taken 57655116 times.
✓ Branch 1 taken 3203062 times.
60858178 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8732 57655116 down_control_states[i] = raw_control_state[i];
8733 3203062 }
8734
8735
2/2
✓ Branch 0 taken 15664532 times.
✓ Branch 1 taken 21 times.
15664553 if (!replay_is_replaying())
8736 {
8737
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[0]=zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset < -STICK_PRECISION : joybtn(DUbtn));
8738
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[1]=zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn));
8739
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[2]=zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn));
8740
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[3]=zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn));
8741
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[4]=zc_getrawkey(Akey, true)||joybtn(Abtn);
8742
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[5]=zc_getrawkey(Bkey, true)||joybtn(Bbtn);
8743
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[6]=zc_getrawkey(Skey, true)||joybtn(Sbtn);
8744
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[7]=zc_getrawkey(Lkey, true)||joybtn(Lbtn);
8745
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[8]=zc_getrawkey(Rkey, true)||joybtn(Rbtn);
8746
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[9]=zc_getrawkey(Pkey, true)||joybtn(Pbtn);
8747
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[10]=zc_getrawkey(Exkey1, true)||joybtn(Exbtn1);
8748
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[11]=zc_getrawkey(Exkey2, true)||joybtn(Exbtn2);
8749
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[12]=zc_getrawkey(Exkey3, true)||joybtn(Exbtn3);
8750
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[13]=zc_getrawkey(Exkey4, true)||joybtn(Exbtn4);
8751
8752
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 if(num_joysticks != 0)
8753 {
8754 raw_control_state[14] = STICK_2_Y.pos - js_stick_2_y_offset < -STICK_PRECISION;
8755 raw_control_state[15] = STICK_2_Y.pos - js_stick_2_y_offset > STICK_PRECISION;
8756 raw_control_state[16] = STICK_2_X.pos - js_stick_2_x_offset < -STICK_PRECISION;
8757 raw_control_state[17] = STICK_2_X.pos - js_stick_2_x_offset > STICK_PRECISION;
8758 }
8759 else
8760 {
8761 21 raw_control_state[14] = false;
8762 21 raw_control_state[15] = false;
8763 21 raw_control_state[16] = false;
8764 21 raw_control_state[17] = false;
8765 }
8766 21 }
8767
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 15664548 times.
15664553 if (replay_is_active())
8768 {
8769
2/2
✓ Branch 0 taken 1211700 times.
✓ Branch 1 taken 14452848 times.
15664548 if (replay_get_version() < 3)
8770 1211700 replay_poll();
8771
4/4
✓ Branch 0 taken 14452827 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 12691452 times.
✓ Branch 3 taken 1761375 times.
14452848 else if (replay_is_replaying() && replay_get_version() < 6)
8772 1761375 replay_peek_input();
8773
4/4
✓ Branch 0 taken 12691452 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 9488390 times.
✓ Branch 3 taken 3203062 times.
12691473 else if (replay_is_replaying() && replay_version_check(8, 11))
8774 3203062 replay_peek_input();
8775
2/2
✓ Branch 0 taken 14324606 times.
✓ Branch 1 taken 1339942 times.
15664548 if (replay_get_version() == 8)
8776 1339942 update_keys();
8777 15664548 }
8778
8779 // Some test replay files were made before a serious input bug was fixed, so instead
8780 // of re-doing them or tossing them out, just check for that zplay version.
8781
3/4
✓ Branch 0 taken 15664543 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 121900 times.
✓ Branch 3 taken 15542643 times.
15664553 bool botched_input = replay_is_active() && replay_get_version() != 1 && replay_get_version() < 8;
8782
2/2
✓ Branch 0 taken 281961774 times.
✓ Branch 1 taken 15664543 times.
297626317 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8783 {
8784 281961774 control_state[i] = raw_control_state[i];
8785
4/4
✓ Branch 0 taken 53024004 times.
✓ Branch 1 taken 228937770 times.
✓ Branch 2 taken 2611994 times.
✓ Branch 3 taken 50412010 times.
281961774 if (botched_input && !control_state[i])
8786 50412010 down_control_states[i] = false;
8787 281961774 }
8788 15664543 bool did_bad_cutscene_btn = false;
8789
2/2
✓ Branch 0 taken 15664543 times.
✓ Branch 1 taken 281961774 times.
297626317 for(int q = 0; q < 18; ++q)
8790
4/4
✓ Branch 0 taken 13340665 times.
✓ Branch 1 taken 268621109 times.
✓ Branch 2 taken 13338954 times.
✓ Branch 3 taken 1711 times.
281963485 if(control_state[q] && !active_cutscene.can_button(q))
8791 {
8792 1711 control_state[q] = false;
8793 1711 did_bad_cutscene_btn = true;
8794 1711 }
8795
2/2
✓ Branch 0 taken 15663276 times.
✓ Branch 1 taken 1267 times.
15664543 if(did_bad_cutscene_btn)
8796 1267 active_cutscene.error();
8797
8798 15664543 button_press[0]=rButton(control_state[0],button_hold[0]);
8799 15664543 button_press[1]=rButton(control_state[1],button_hold[1]);
8800 15664543 button_press[2]=rButton(control_state[2],button_hold[2]);
8801 15664543 button_press[3]=rButton(control_state[3],button_hold[3]);
8802 15664543 button_press[4]=rButton(control_state[4],button_hold[4]);
8803 15664543 button_press[5]=rButton(control_state[5],button_hold[5]);
8804 15664543 button_press[6]=rButton(control_state[6],button_hold[6]);
8805 15664543 button_press[7]=rButton(control_state[7],button_hold[7]);
8806 15664543 button_press[8]=rButton(control_state[8],button_hold[8]);
8807 15664543 button_press[9]=rButton(control_state[9],button_hold[9]);
8808 15664543 button_press[10]=rButton(control_state[10],button_hold[10]);
8809 15664543 button_press[11]=rButton(control_state[11],button_hold[11]);
8810 15664543 button_press[12]=rButton(control_state[12],button_hold[12]);
8811 15664543 button_press[13]=rButton(control_state[13],button_hold[13]);
8812 15664543 button_press[14]=rButton(control_state[14],button_hold[14]);
8813 15664543 button_press[15]=rButton(control_state[15],button_hold[15]);
8814 15664543 button_press[16]=rButton(control_state[16],button_hold[16]);
8815 15664543 button_press[17]=rButton(control_state[17],button_hold[17]);
8816 15664543 }
8817
8818 // Returns true if any game key is pressed. This is needed because keypressed()
8819 // doesn't detect modifier keys and control_state[] can be modified by scripts.
8820 78785999 bool zc_key_pressed()
8821 //may also need to use zc_getrawkey
8822 {
8823
7/10
✓ Branch 0 taken 63631993 times.
✓ Branch 1 taken 15154006 times.
✓ Branch 2 taken 15154006 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15154006 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12418197 times.
✓ Branch 7 taken 12418197 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4960120 times.
83746119 if((zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset< -STICK_PRECISION : joybtn(DUbtn))) ||
8824
4/6
✓ Branch 0 taken 12418197 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12418197 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9454594 times.
✓ Branch 5 taken 9454594 times.
12418197 (zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn))) ||
8825
4/6
✓ Branch 0 taken 9454594 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9454594 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6256717 times.
✓ Branch 5 taken 6256717 times.
9454594 (zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn))) ||
8826
4/6
✓ Branch 0 taken 6256717 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6256717 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5369386 times.
✓ Branch 5 taken 5369386 times.
6256717 (zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn))) ||
8827
1/2
✓ Branch 0 taken 5369386 times.
✗ Branch 1 not taken.
5369386 (zc_getrawkey(Akey, true)||joybtn(Abtn)) ||
8828
3/4
✓ Branch 0 taken 5182086 times.
✓ Branch 1 taken 187300 times.
✓ Branch 2 taken 5182086 times.
✗ Branch 3 not taken.
5369386 (zc_getrawkey(Bkey, true)||joybtn(Bbtn)) ||
8829
3/4
✓ Branch 0 taken 5035153 times.
✓ Branch 1 taken 146933 times.
✓ Branch 2 taken 5035153 times.
✗ Branch 3 not taken.
5182086 (zc_getrawkey(Skey, true)||joybtn(Sbtn)) ||
8830
3/4
✓ Branch 0 taken 5012936 times.
✓ Branch 1 taken 22217 times.
✓ Branch 2 taken 5012936 times.
✗ Branch 3 not taken.
5035153 (zc_getrawkey(Lkey, true)||joybtn(Lbtn)) ||
8831
3/4
✓ Branch 0 taken 4986567 times.
✓ Branch 1 taken 26369 times.
✓ Branch 2 taken 4986567 times.
✗ Branch 3 not taken.
5012936 (zc_getrawkey(Rkey, true)||joybtn(Rbtn)) ||
8832
3/4
✓ Branch 0 taken 4979282 times.
✓ Branch 1 taken 7285 times.
✓ Branch 2 taken 4979282 times.
✗ Branch 3 not taken.
4986567 (zc_getrawkey(Pkey, true)||joybtn(Pbtn)) ||
8833
3/4
✓ Branch 0 taken 4962043 times.
✓ Branch 1 taken 17239 times.
✓ Branch 2 taken 4962043 times.
✗ Branch 3 not taken.
4979282 (zc_getrawkey(Exkey1, true)||joybtn(Exbtn1)) ||
8834
3/4
✓ Branch 0 taken 4960214 times.
✓ Branch 1 taken 1829 times.
✓ Branch 2 taken 4960214 times.
✗ Branch 3 not taken.
4962043 (zc_getrawkey(Exkey2, true)||joybtn(Exbtn2)) ||
8835
3/4
✓ Branch 0 taken 4960179 times.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 4960179 times.
✗ Branch 3 not taken.
4960214 (zc_getrawkey(Exkey3, true)||joybtn(Exbtn3)) ||
8836
2/2
✓ Branch 0 taken 4960120 times.
✓ Branch 1 taken 59 times.
4960179 (zc_getrawkey(Exkey4, true)||joybtn(Exbtn4))) // Skipping joystick axes
8837 140823667 return true;
8838
8839 4960120 return false;
8840 18519801 }
8841
8842 299949789 bool getInput(int32_t btn, int input_flags)
8843 {
8844
3/4
✓ Branch 0 taken 267055517 times.
✓ Branch 1 taken 32894272 times.
✓ Branch 2 taken 267055517 times.
✗ Branch 3 not taken.
299949789 if((input_flags & INPUT_HERO_ACTION) && Hero.no_control())
8845 return false;
8846
8847 299949789 bool press = input_flags & INPUT_PRESS;
8848 299949789 bool drunk = input_flags & INPUT_DRUNK;
8849 299949789 bool ignoreDisable = input_flags & INPUT_IGNORE_DISABLE;
8850 299949789 bool eatEntirely = input_flags & INPUT_EAT_ENTIRELY;
8851 299949789 bool peek = input_flags & INPUT_PEEK;
8852
8853 299949789 bool ret = false, drunkstate = false, rawret = false;;
8854 299949789 bool* flag = &down_control_states[btn];
8855
2/7
✓ Branch 0 taken 281411081 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 18538708 times.
299949789 switch(btn)
8856 {
8857 case btnF12:
8858 ret = zc_getkey(KEY_F12, ignoreDisable);
8859 rawret = zc_getrawkey(KEY_F12, ignoreDisable);
8860 eatEntirely = false;
8861 break;
8862 case btnF11:
8863 ret = zc_getkey(KEY_F11, ignoreDisable);
8864 rawret = zc_getrawkey(KEY_F11, ignoreDisable);
8865 eatEntirely = false;
8866 break;
8867 case btnF5:
8868 ret = zc_getkey(KEY_F5, ignoreDisable);
8869 rawret = zc_getrawkey(KEY_F5, ignoreDisable);
8870 eatEntirely = false;
8871 break;
8872 case btnQ:
8873 ret = zc_getkey(KEY_Q, ignoreDisable);
8874 rawret = zc_getrawkey(KEY_Q, ignoreDisable);
8875 eatEntirely = false;
8876 break;
8877 case btnI:
8878 ret = zc_getkey(KEY_I, ignoreDisable);
8879 rawret = zc_getrawkey(KEY_I, ignoreDisable);
8880 eatEntirely = false;
8881 break;
8882 case btnM:
8883
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18538708 times.
18538708 if(FFCore.kb_typing_mode) return false;
8884 18538708 rawret = ret = zc_getrawkey(KEY_ESC, ignoreDisable);
8885 18538708 eatEntirely = false;
8886 18538708 break;
8887 default: //control_state[] index
8888
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 281411081 times.
281411081 if(FFCore.kb_typing_mode) return false;
8889
6/6
✓ Branch 0 taken 280031667 times.
✓ Branch 1 taken 1379414 times.
✓ Branch 2 taken 18073746 times.
✓ Branch 3 taken 261957921 times.
✓ Branch 4 taken 18070773 times.
✓ Branch 5 taken 2973 times.
281411081 if(!ignoreDisable && get_qr(qr_FIXDRUNKINPUTS) && disable_control[btn]) drunk = false;
8890
2/2
✓ Branch 0 taken 15930325 times.
✓ Branch 1 taken 265477783 times.
281408108 else if(btn<11) drunkstate = drunk_toggle_state[btn];
8891
4/4
✓ Branch 0 taken 250110087 times.
✓ Branch 1 taken 31300994 times.
✓ Branch 2 taken 7136 times.
✓ Branch 3 taken 31293858 times.
312712075 ret = control_state[btn] && (ignoreDisable || !disable_control[btn]);
8892 281411081 rawret = raw_control_state[btn];
8893 281411081 }
8894
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 299949789 times.
299949789 assert(flag);
8895
2/2
✓ Branch 0 taken 192502040 times.
✓ Branch 1 taken 107447749 times.
299949789 if(press)
8896 {
8897
2/2
✓ Branch 0 taken 4643423 times.
✓ Branch 1 taken 102804326 times.
107447749 if(peek)
8898 4643423 ret = rButtonPeek(ret, *flag);
8899
2/2
✓ Branch 0 taken 94951314 times.
✓ Branch 1 taken 7853012 times.
102804326 else if(get_qr(qr_BROKEN_INPUT_DOWN_STATE)) ret = rButton(ret, *flag);
8900 7853012 else ret = rButton(ret, *flag, rawret);
8901 107447749 }
8902
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 299949789 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
299949789 if(eatEntirely && ret) control_state[btn] = false;
8903
4/4
✓ Branch 0 taken 224466251 times.
✓ Branch 1 taken 75483538 times.
✓ Branch 2 taken 224466170 times.
✓ Branch 3 taken 81 times.
299949789 if(drunk && drunkstate) ret = !ret;
8904 299949789 return ret;
8905 299949789 }
8906
8907 15041733 byte getIntBtnInput(byte intbtn, int input_flags)
8908 {
8909 15041733 byte ret = 0;
8910
2/2
✓ Branch 0 taken 10620570 times.
✓ Branch 1 taken 4421163 times.
15041733 if(intbtn & INT_BTN_A) ret |= getInput(btnA, input_flags) ? INT_BTN_A : 0;
8911
2/2
✓ Branch 0 taken 14832767 times.
✓ Branch 1 taken 208966 times.
15041733 if(intbtn & INT_BTN_B) ret |= getInput(btnB, input_flags) ? INT_BTN_B : 0;
8912
2/2
✓ Branch 0 taken 14834085 times.
✓ Branch 1 taken 207648 times.
15041733 if(intbtn & INT_BTN_L) ret |= getInput(btnL, input_flags) ? INT_BTN_L : 0;
8913
2/2
✓ Branch 0 taken 14834085 times.
✓ Branch 1 taken 207648 times.
15041733 if(intbtn & INT_BTN_R) ret |= getInput(btnR, input_flags) ? INT_BTN_R : 0;
8914
2/2
✓ Branch 0 taken 14834085 times.
✓ Branch 1 taken 207648 times.
15041733 if(intbtn & INT_BTN_EX1) ret |= getInput(btnEx1, input_flags) ? INT_BTN_EX1 : 0;
8915
2/2
✓ Branch 0 taken 14834085 times.
✓ Branch 1 taken 207648 times.
15041733 if(intbtn & INT_BTN_EX2) ret |= getInput(btnEx2, input_flags) ? INT_BTN_EX2 : 0;
8916
2/2
✓ Branch 0 taken 14834085 times.
✓ Branch 1 taken 207648 times.
15041733 if(intbtn & INT_BTN_EX3) ret |= getInput(btnEx3, input_flags) ? INT_BTN_EX3 : 0;
8917
2/2
✓ Branch 0 taken 14833970 times.
✓ Branch 1 taken 207763 times.
15041733 if(intbtn & INT_BTN_EX4) ret |= getInput(btnEx4, input_flags) ? INT_BTN_EX4 : 0;
8918 15041733 return ret; //No early return, to make sure all button presses are eaten that should be! -Em
8919 }
8920
8921 7513 byte checkIntBtnVal(byte intbtn, byte vals)
8922 {
8923 7513 return intbtn&vals;
8924 }
8925
8926 208698 bool Up()
8927 {
8928 208698 return getInput(btnUp);
8929 }
8930 208697 bool Down()
8931 {
8932 208697 return getInput(btnDown);
8933 }
8934 208697 bool Left()
8935 {
8936 208697 return getInput(btnLeft);
8937 }
8938 208697 bool Right()
8939 {
8940 208697 return getInput(btnRight);
8941 }
8942 530261 bool cAbtn()
8943 {
8944 530261 return getInput(btnA);
8945 }
8946 3306494 bool cBbtn()
8947 {
8948 3306494 return getInput(btnB);
8949 }
8950 bool cSbtn()
8951 {
8952 return getInput(btnS);
8953 }
8954 208608 bool cLbtn()
8955 {
8956 208608 return getInput(btnL);
8957 }
8958 208608 bool cRbtn()
8959 {
8960 208608 return getInput(btnR);
8961 }
8962 bool cPbtn()
8963 {
8964 return getInput(btnP);
8965 }
8966 bool cEx1btn()
8967 {
8968 return getInput(btnEx1);
8969 }
8970 bool cEx2btn()
8971 {
8972 return getInput(btnEx2);
8973 }
8974 bool cEx3btn()
8975 {
8976 return getInput(btnEx3);
8977 }
8978 bool cEx4btn()
8979 {
8980 return getInput(btnEx4);
8981 }
8982 bool AxisUp()
8983 {
8984 return getInput(btnAxisUp);
8985 }
8986 bool AxisDown()
8987 {
8988 return getInput(btnAxisDown);
8989 }
8990 bool AxisLeft()
8991 {
8992 return getInput(btnAxisLeft);
8993 }
8994 bool AxisRight()
8995 {
8996 return getInput(btnAxisRight);
8997 }
8998
8999 bool cMbtn()
9000 {
9001 return getInput(btnM);
9002 }
9003 bool cF12()
9004 {
9005 return getInput(btnF12);
9006 }
9007 bool cF11()
9008 {
9009 return getInput(btnF11);
9010 }
9011 bool cF5()
9012 {
9013 return getInput(btnF5);
9014 }
9015 bool cQ()
9016 {
9017 return getInput(btnQ);
9018 }
9019 bool cI()
9020 {
9021 return getInput(btnI);
9022 }
9023
9024 211312 bool rUp()
9025 {
9026 211312 return getInput(btnUp, INPUT_PRESS);
9027 }
9028 211099 bool rDown()
9029 {
9030 211099 return getInput(btnDown, INPUT_PRESS);
9031 }
9032 210903 bool rLeft()
9033 {
9034 210903 return getInput(btnLeft, INPUT_PRESS);
9035 }
9036 210163 bool rRight()
9037 {
9038 210163 return getInput(btnRight, INPUT_PRESS);
9039 }
9040 4648 bool rAbtn()
9041 {
9042 4648 return getInput(btnA, INPUT_PRESS);
9043 }
9044 bool rBbtn()
9045 {
9046 return getInput(btnB, INPUT_PRESS);
9047 }
9048 210364 bool rSbtn()
9049 {
9050 210364 return getInput(btnS, INPUT_PRESS);
9051 }
9052 18519801 bool rMbtn()
9053 {
9054 18519801 return getInput(btnM, INPUT_PRESS);
9055 }
9056 186046 bool rLbtn()
9057 {
9058 186046 return getInput(btnL, INPUT_PRESS);
9059 }
9060 186041 bool rRbtn()
9061 {
9062 186041 return getInput(btnR, INPUT_PRESS);
9063 }
9064 208608 bool rPbtn()
9065 {
9066 208608 return getInput(btnP, INPUT_PRESS);
9067 }
9068 bool rEx1btn()
9069 {
9070 return getInput(btnEx1, INPUT_PRESS);
9071 }
9072 bool rEx2btn()
9073 {
9074 return getInput(btnEx2, INPUT_PRESS);
9075 }
9076 186037 bool rEx3btn()
9077 {
9078 186037 return getInput(btnEx3, INPUT_PRESS);
9079 }
9080 186037 bool rEx4btn()
9081 {
9082 186037 return getInput(btnEx4, INPUT_PRESS);
9083 }
9084 bool rAxisUp()
9085 {
9086 return getInput(btnAxisUp, INPUT_PRESS);
9087 }
9088 bool rAxisDown()
9089 {
9090 return getInput(btnAxisDown, INPUT_PRESS);
9091 }
9092 bool rAxisLeft()
9093 {
9094 return getInput(btnAxisLeft, INPUT_PRESS);
9095 }
9096 bool rAxisRight()
9097 {
9098 return getInput(btnAxisRight, INPUT_PRESS);
9099 }
9100
9101 bool rF11()
9102 {
9103 return getInput(btnF11, INPUT_PRESS);
9104 }
9105 bool rQ()
9106 {
9107 return getInput(btnQ, INPUT_PRESS);
9108 }
9109 bool rI()
9110 {
9111 return getInput(btnI, INPUT_PRESS);
9112 }
9113
9114 bool DrunkUp()
9115 {
9116 return getInput(btnUp, INPUT_DRUNK);
9117 }
9118 bool DrunkDown()
9119 {
9120 return getInput(btnDown, INPUT_DRUNK);
9121 }
9122 bool DrunkLeft()
9123 {
9124 return getInput(btnLeft, INPUT_DRUNK);
9125 }
9126 bool DrunkRight()
9127 {
9128 return getInput(btnRight, INPUT_DRUNK);
9129 }
9130 bool DrunkcAbtn()
9131 {
9132 return getInput(btnA, INPUT_DRUNK);
9133 }
9134 bool DrunkcBbtn()
9135 {
9136 return getInput(btnB, INPUT_DRUNK);
9137 }
9138 bool DrunkcEx1btn()
9139 {
9140 return getInput(btnEx1, INPUT_DRUNK);
9141 }
9142 bool DrunkcEx2btn()
9143 {
9144 return getInput(btnEx2, INPUT_DRUNK);
9145 }
9146 bool DrunkcSbtn()
9147 {
9148 return getInput(btnS, INPUT_DRUNK);
9149 }
9150 bool DrunkcMbtn()
9151 {
9152 return getInput(btnM, INPUT_DRUNK);
9153 }
9154 bool DrunkcLbtn()
9155 {
9156 return getInput(btnL, INPUT_DRUNK);
9157 }
9158 bool DrunkcRbtn()
9159 {
9160 return getInput(btnR, INPUT_DRUNK);
9161 }
9162 bool DrunkcPbtn()
9163 {
9164 return getInput(btnP, INPUT_DRUNK);
9165 }
9166
9167 bool DrunkrUp()
9168 {
9169 return getInput(btnUp, INPUT_PRESS | INPUT_DRUNK);
9170 }
9171 bool DrunkrDown()
9172 {
9173 return getInput(btnDown, INPUT_PRESS | INPUT_DRUNK);
9174 }
9175 bool DrunkrLeft()
9176 {
9177 return getInput(btnLeft, INPUT_PRESS | INPUT_DRUNK);
9178 }
9179 bool DrunkrRight()
9180 {
9181 return getInput(btnRight, INPUT_PRESS | INPUT_DRUNK);
9182 }
9183 bool DrunkrAbtn()
9184 {
9185 return getInput(btnA, INPUT_PRESS | INPUT_DRUNK);
9186 }
9187 bool DrunkrBbtn()
9188 {
9189 return getInput(btnB, INPUT_PRESS | INPUT_DRUNK);
9190 }
9191 bool DrunkrEx1btn()
9192 {
9193 return getInput(btnEx1, INPUT_PRESS | INPUT_DRUNK);
9194 }
9195 bool DrunkrEx2btn()
9196 {
9197 return getInput(btnEx2, INPUT_PRESS | INPUT_DRUNK);
9198 }
9199 bool DrunkrEx3btn()
9200 {
9201 return getInput(btnEx3, INPUT_PRESS | INPUT_DRUNK);
9202 }
9203 bool DrunkrEx4btn()
9204 {
9205 return getInput(btnEx4, INPUT_PRESS | INPUT_DRUNK);
9206 }
9207 bool DrunkrSbtn()
9208 {
9209 return getInput(btnS, INPUT_PRESS | INPUT_DRUNK);
9210 }
9211 bool DrunkrMbtn()
9212 {
9213 return getInput(btnM, INPUT_PRESS | INPUT_DRUNK);
9214 }
9215 bool DrunkrLbtn()
9216 {
9217 return getInput(btnL, INPUT_PRESS | INPUT_DRUNK);
9218 }
9219 bool DrunkrRbtn()
9220 {
9221 return getInput(btnR, INPUT_PRESS | INPUT_DRUNK);
9222 }
9223 bool DrunkrPbtn()
9224 {
9225 return getInput(btnP, INPUT_PRESS | INPUT_DRUNK);
9226 }
9227
9228 18907 void eat_buttons()
9229 {
9230 18907 getInput(btnA, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9231 18907 getInput(btnB, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9232 18907 getInput(btnS, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9233 18907 getInput(btnM, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9234 18907 getInput(btnL, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9235 18907 getInput(btnR, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9236 18907 getInput(btnP, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9237 18907 getInput(btnEx1, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9238 18907 getInput(btnEx2, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9239 18907 getInput(btnEx3, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9240 18907 getInput(btnEx4, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9241 18907 }
9242
9243 // Is true for the _first frame_ of a key press.
9244 // But! it is possible that a script manually sets the value of KeyPress,
9245 // in which case it will be restored to the "true" value based on `key_current_frame`
9246 // and `key_previous_frame` on the next frame.
9247 46 bool zc_readkey(int32_t k, bool ignoreDisable)
9248 {
9249
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(ignoreDisable) return KeyPress[k];
9250
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 switch(k)
9251 {
9252 case KEY_F7:
9253 case KEY_F8:
9254 case KEY_F9:
9255 return KeyPress[k];
9256
9257 default:
9258
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 return KeyPress[k] && !disabledKeys[k];
9259 }
9260 46 }
9261
9262 // Is true for _every frame_ a key is held down.
9263 // But! it is possible that a script manually sets the value of KeyInput,
9264 // in which case it will be restored to the "true" value based on `key_current_frame`
9265 // on the next frame.
9266 bool zc_getkey(int32_t k, bool ignoreDisable)
9267 {
9268 if(ignoreDisable) return KeyInput[k];
9269 switch(k)
9270 {
9271 case KEY_F7:
9272 case KEY_F8:
9273 case KEY_F9:
9274 return KeyInput[k];
9275
9276 default:
9277 return KeyInput[k] && !disabledKeys[k];
9278 }
9279 }
9280
9281 // Reads (and then clears) the current frame key state directly.
9282 // Scripts can also modify `key_current_frame`.
9283 900 bool zc_readrawkey(int32_t k, bool ignoreDisable)
9284 {
9285
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 898 times.
900 if(zc_getrawkey(k, ignoreDisable))
9286 {
9287 2 _key[k]=key[k]=key_current_frame[k]=0;
9288 2 return true;
9289 }
9290 898 _key[k]=key[k]=key_current_frame[k]=0;
9291 898 return false;
9292 900 }
9293
9294 // Reads the current frame key state directly.
9295 // Scripts can also modify `key_current_frame`.
9296 125791063 bool zc_getrawkey(int32_t k, bool ignoreDisable)
9297 {
9298
2/2
✓ Branch 0 taken 107271170 times.
✓ Branch 1 taken 18519893 times.
125791063 if(ignoreDisable) return key_current_frame[k];
9299
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18519893 times.
18519893 switch(k)
9300 {
9301 case KEY_F7:
9302 case KEY_F8:
9303 case KEY_F9:
9304 return key_current_frame[k];
9305
9306 default:
9307
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18519893 times.
18519893 return key_current_frame[k] && !disabledKeys[k];
9308 }
9309 125791063 }
9310
9311 // Only used for a handful of keys, like tilde and Function keys.
9312 // This state is never read within the game.
9313 // It exists so that all keyboard input still functions during replay,
9314 // without inadvertently doing things like toggling throttling if the player
9315 // presses ~
9316 bool zc_get_system_key(int32_t k)
9317 {
9318 return key_system[k];
9319 }
9320
9321 // True for the _first_ frame of a key press.
9322 166678209 bool zc_read_system_key(int32_t k)
9323 {
9324 166678209 return key_system_press[k];
9325 }
9326
9327 2352014727 bool is_system_key(int32_t k)
9328 {
9329
2/2
✓ Branch 0 taken 2185336518 times.
✓ Branch 1 taken 166678209 times.
2352014727 switch (k)
9330 {
9331 case KEY_BACKQUOTE:
9332 case KEY_CLOSEBRACE:
9333 case KEY_END:
9334 case KEY_HOME:
9335 case KEY_OPENBRACE:
9336 case KEY_PGDN:
9337 case KEY_PGUP:
9338 case KEY_TAB:
9339 case KEY_TILDE:
9340 166678209 return true;
9341 }
9342 2185336518 return is_Fkey(k);
9343 2352014727 }
9344
9345 18519801 void update_system_keys()
9346 {
9347
2/2
✓ Branch 0 taken 2352014727 times.
✓ Branch 1 taken 18519801 times.
2370534528 for (int32_t q = 0; q < 127; ++q)
9348 {
9349
2/2
✓ Branch 0 taken 388915821 times.
✓ Branch 1 taken 1963098906 times.
2352014727 if (!is_system_key(q))
9350 1963098906 continue;
9351
9352 388915821 key_system[q] = key[q];
9353
1/2
✓ Branch 0 taken 388915821 times.
✗ Branch 1 not taken.
388915821 key_system_press[q] = key_system[q] && !key_system_previous[q];
9354 388915821 key_system_previous[q] = key_system[q];
9355 388915821 }
9356 18519801 }
9357
9358 19859743 void update_keys()
9359 {
9360
2/2
✓ Branch 0 taken 2522187361 times.
✓ Branch 1 taken 19859743 times.
2542047104 for (int32_t q = 0; q < 127; ++q)
9361 {
9362 // When replaying, replay.cpp takes care of updating `key_current_frame`.
9363
2/2
✓ Branch 0 taken 2522174661 times.
✓ Branch 1 taken 12700 times.
2522187361 if (!replay_is_replaying())
9364 12700 key_current_frame[q] = key[q];
9365
9366
2/2
✓ Branch 0 taken 2502802703 times.
✓ Branch 1 taken 19384658 times.
2522187361 KeyPress[q] = key_current_frame[q] && !key_previous_frame[q];
9367 2522187361 KeyInput[q] = key_current_frame[q];
9368 2522187361 key_previous_frame[q] = key_current_frame[q];
9369 2522187361 }
9370 19859743 }
9371
9372